Initial commit
This commit is contained in:
24
Assets/Scripts/PlayerKick.cs
Normal file
24
Assets/Scripts/PlayerKick.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerKick : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float kickForce = 8f;
|
||||
|
||||
private void OnControllerColliderHit(ControllerColliderHit hit)
|
||||
{
|
||||
if (hit.collider.CompareTag("Ball"))
|
||||
{
|
||||
Rigidbody rb = hit.collider.GetComponent<Rigidbody>();
|
||||
|
||||
if (rb != null)
|
||||
{
|
||||
Vector3 direction = hit.moveDirection;
|
||||
direction.y = 0.3f;
|
||||
|
||||
rb.AddForce(direction * kickForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user