You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1011 B
38 lines
1011 B
using System;
|
|
using UnityEngine;
|
|
|
|
public class IceBlockPush : MonoBehaviour
|
|
{
|
|
[SerializeField] float contactForce = 2.5f;
|
|
private Rigidbody rb;
|
|
|
|
private void Start()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
|
|
if (other.GetComponent<CapsuleCollider>())
|
|
{
|
|
Push(other.transform.position);
|
|
}
|
|
}
|
|
|
|
private void Push(Vector3 position)
|
|
{
|
|
Vector3 diffrenceVector = rb.transform.position - position;
|
|
diffrenceVector.y = 0;
|
|
//jetzt Vecort auf rechts,links, oben oder unten
|
|
Vector3 directionVector =
|
|
Mathf.Abs(diffrenceVector.x) > Mathf.Abs(diffrenceVector.z)
|
|
? new Vector3(Mathf.Sign(diffrenceVector.x), 0, 0)
|
|
: new Vector3(0, 0, Mathf.Sign(diffrenceVector.z));
|
|
|
|
//Debug.DrawRay(transform.position, directionVector * 3f, Color.red);
|
|
|
|
rb.AddForce(directionVector * contactForce, ForceMode.Impulse);
|
|
}
|
|
}
|