- Home /
Slowly rotate a body whilst adding a force to its rigidbody
Hi , I am making a endless jetpack game where depending on which half of the screen the user taps , the jetpack goes in that direction. I basically want the object to tilt slowly and gradually to the left if its to go there or vice versa.(like Jetpack Jinx). I have tried Lerp , quaternion and a couple others all seem to be jerky . The way i move the jetpack to the left and right is using addforce so somtimes when the rotation is not zero and a force is applied it suddenly jumps up awkwardly . Please help me solve this conundrum of mine , thanks !
if (Input.GetMouseButtonDown (0)) {
GetComponent<Rigidbody2D>().AddForce(new Vector2(0f,forceY));
if (Input.mousePosition.x < Screen.width / 2 || Input.GetKey (KeyCode.LeftArrow))
{
GetComponent<Rigidbody2D>().velocity=new Vector2(0f,0f);
GetComponent<Rigidbody2D>().AddForce(new Vector2(-forceX,0f));
}
else if (Input.mousePosition.x > Screen.width / 2 || Input.GetKey (KeyCode.RightArrow))
{
GetComponent<Rigidbody2D>().velocity=new Vector2(0f,0f);
GetComponent<Rigidbody2D>().AddRelativeForce(new Vector2(forceX,0f));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220611230010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get Steering Wheel Rotation angle? 1 Answer
Rotation with fixed position . , 1 Answer
Car tutorial physics models rotating randomly? 1 Answer
Transform a gameobject y rotation to another gameobject y rotation 1 Answer
How to Rotate Character and move in direction character is facing? 2 Answers