How do I set a constant speed on a 2d joystick movement script?,Constant speed on 2d joystick top-down movement
Hi, I'm struggling with how to make it so that my spaceship has a constant speed, and joystick movement doesn't change the speed, only what direction the spaceship is flying. Also, I want to have a my spaceship rotate slower, around a 'circle' like not a literal one. But i want to make it so that you cant make an instant u-turn. If you want a reference, i'm trying to make my movement exactly like the game 'Missiles'. Here's my movement script.
public class Airplane : MonoBehaviour { public Rigidbody2D rb; public VariableJoystick joystick; public float speed;
Vector2 moveDirection;
// Update is called once per frame
void Update()
{
MyInput();
}
void FixedUpdate()
{
Movement();
}
void MyInput()
{
float x = joystick.Horizontal;
float y = joystick.Vertical;
moveDirection = new Vector2(x, y);
}
void Movement()
{
rb.velocity = moveDirection * speed;
if (rb.velocity != Vector2.zero)
{
transform.up = rb.velocity;
}
}
}
Your answer
Follow this Question
Related Questions
Player doesn't face in direction of its last movement direction 0 Answers
Isometric movement for MoveTowards 0 Answers
Making 2d grid movement 0 Answers
My 2d movement script isn't working 0 Answers
2D Platformer, Icy material? 0 Answers