0
Every time I move the object it tends to rotate, due to its natural motion, but when it rotates it changes the x-axis, causing its movement to be confused by losing the reference of the axis. How do I make the rotation does not influence the x-axis?
public class teste : MonoBehaviour
{
public float forca = 300f;
public Rigidbody2D Bola;
public float movdir = 5f;
public float moveesq = -5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Bola.AddForce(new Vector2(0, forca * Time.deltaTime), ForceMode2D.Impulse);
}
if (Input.GetKey(KeyCode.RightArrow))
{
Bola.transform.Translate(new Vector2(movdir * Time.deltaTime, 0));
}
if (Input.GetKey(KeyCode.LeftArrow))
{
Bola.transform.Translate(new Vector2(moveesq * Time.deltaTime, 0));
}
}
}
You’re talking about rotation, but at no time did you use the rotation Transform,
Bola.transform.Rotate();
– FourZeroFive
Yes, because in game when the object is in motion it rotates on its own physics. I have no problem with the rotation itself, but the fact that it changes my x-axis
– Lucas Ferraz
In classical mechanics, when you rotate something in one direction it tends to rotate in the opposite direction, which can generate a change in the x axis, due to Newton’s law of action and reaction, I recommend looking at the object options in Unity that deal with physics, such as cinematic, Dynamic, Static and etc.
– FourZeroFive