- Home /
Unity 2D: How to move object in an pre defined path?
Sorry my bad, I should have asked this question first So the thing is that I want my gameobject(rock) to follow an arc, something like that in the picture below, it must follow a certain path on which it would travel, in the beginning it will not be in the game scene it should only come after the game starts and then follow that pre defined path and exit the game scene and get destroyed. But I'm just not getting how to do it, I searched alot so if you can help me I would really really appreciate
@thor348k thanks alot for taking out your precious time and answering me
Answer by thor348k · May 30, 2019 at 03:58 AM
If you don't want to move it with math, such as calculating it's height per bounce, velocity, mass, etc., you could attach a Rigidbody2D to it.
Set the spawn point (position off screen), and when it spawns, add a horizontal force to it (negative to push left). Play with its mass, angular drag, etc. If you add a custom PhysicsMaterial2D to it, you can even play with the bounce and friction.
For more of a "random" experience, you could make the spawn points have a random y position that's defined by a range. Then, when adding the horizontal force, you could have that be random within a range. Maybe even have the bounce or mass be random!
But maybe you don't want to use physics here, and have them follow the same path each time. Then you'd just create a Vector2 array, and set each one so they form the path. Then iterate through moving the rock to each point.
Hope this helps! @KimMingyuSVT
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Argument out of range. Parameter name: index 1 Answer
How to call child overide function? 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer