How to add a startforce to a rigidbody 2D but let gravity take it from there?
Hi,
I'm making a 2D platformer game and now I want to trow a ball. The ball has to collide with everything except my player. So I added a rigidbody 2D and a trigger collider, I also added a child with a normal collider (with different layers so I can filter what I want to collide with).
Now the physics are working just fine, the ball is bouncing of everything but it's not yet starting with a velocity. Now it just starts and let gravity do his thing.
What I want is to give my object a start speed depending on how I possition my joystick (xbox controller). Calculating the angle isn't hard but for now a fixed angle will be fine. If I add force on awake, I see I can make it move but it seems that the force stays there. (like I make it go right, it collides with a wall, bounces left but the force makes it go right again). Is there any way to fix this?
Thanks allot guys!
Answer by Xercium · May 06, 2016 at 07:09 PM
GetComponent<Rigidbody2D>().AddForce(new Vector3 (1,1) * startDirection * moveSpeed, ForceMode2D.Impulse);
This would do the trick.
Your answer
Follow this Question
Related Questions
2D Collision Point 0 Answers
Add force random movement and random rotation [2D] 1 Answer
Rigidbody.addForce is not working 10 Answers
How do I slow down player movement after OnTriggerEnter 0 Answers
How do I add forces for the specific sprites of a particle? 0 Answers