When my character touches a spring object, he flies up into the air as expected, but when he comes back down again, he falls through the spring and does nothing, i then have to get my character to walk outside the object then back in again to activate it. what am i doing wrong?
using UnityEngine;
using System.Collections;
public class Spring : MonoBehaviour {
public GameObject player;
private Rigidbody RbPlayer;
public int springAmount;
//private bool springHit = false;
// Use this for initialization
void Start () {
RbPlayer = player.GetComponent<Rigidbody>();
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Spring")
{
// springHit = true;
RbPlayer.AddForce (new Vector3 (0, springAmount,0));
}
}
}
In order for AddForce to work, it needs to counteract the force of you coming down. This worked for me, you’ll probably have to tone down the amount of force you apply.
Your builds up velocity when he is falling. It works the first time, because you have no downward velocity. So you need to counteract the -y velocity. I tried to post this before but it got deleted.