- Home /
Question by
jasoncosma · Jul 13, 2012 at 07:18 PM ·
2drigidbodyforce
How to smoothly add force to a rigidbody?
Okay, so I've made a bouncy platform in my 2D platformer that bounces the player up when they jump on it. The problem is when the player jumps on the platform, it adds the force instantly and it looks like the player just teleports upwards very quickly. Is there any way to make it add force smoothly so it doesn't look so unnatural?
Here's my code:
var player : GameObject;
player = GameObject.Find("Player");
function OnTriggerEnter(Trigger : Collider)
{
if (Trigger.gameObject.tag == "Player") // if player collides
{
Debug.Log ("Trampoline collision detected"); // print that it's detected
player.rigidbody.AddForce(0, 20000, 0); // add force up on player
}
}
function OnTriggerExit(Trigger : Collider)
{
if (Trigger.gameObject.tag == "Player") // if player leaves collider
{
player.GetComponent(Rigidbody).isKinematic = true; // remove player's rigidbody
yield WaitForSeconds (0.3); // wait 0.3 seconds
player.GetComponent(Rigidbody).isKinematic = false; // re-add player's rigibody
}
}
Comment
Answer by Mold · Jul 13, 2012 at 08:30 PM
Add smaller force?
and make the force relative
rigidbody.AddRelativeForce(0,x,0);
Your answer
Follow this Question
Related Questions
Adding 1 frame of force 2 Answers
Problem with Force on rigidbody, not always the same force 0 Answers
2D Mouse Look with Collisions 1 Answer
RigidbodyFirstPersonController and external forces... 0 Answers
Adding force to rigidbody 1 Answer