- Home /
How to make a object move right automatically in 2d.
I am trying to make a game were you automatically move right, I am having trouble finding a way to do so. If you can help that would be appreciated.
Answer by aidan7501 · Feb 25, 2019 at 08:32 PM
To make a transform move automatically, you just have to update the transform by translating the object. Put this into your update function -->
transform.Translate(Vector2.right * Time.deltaTime);
Thanks! But is there a way for me to make the movement faster?
Yes there is, multiply the direction value by a speed multiplier. so it would look like
float speed$$anonymous$$ultiplier = 25;
Update()
{
transform.Translate(Vector2.right * Time.deltaTime * speed$$anonymous$$ultiplier);
}
Answer by jmgotsoul · Feb 25, 2019 at 08:32 PM
I'm a noob user so others may have better answers but I think something like this would work:
void Update() {
// I use similar code to this in a simple 2D game I'm building.
// In my code I set speed to a random value based on configuration.
// In your code you would just do whatever makes sense.
transform.Translate(Vector3.right * _speed * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
2D Zig-zag movement and rotation 1 Answer
Sprite will not roate when arrow keys are pressed 2 Answers
[2D] Moving the player 1 tile at a time using rigidbody movement 0 Answers
2D game with two point perspective and distortion? 1 Answer
Unity2D Space shooter rotation resetting when analogue stick input has ended 1 Answer