- Home /
Complex 2D movement (X,Y) using velocity.
I have an entity in my scene that can only move in 2D space (sidescrolling) and its velocity can be affected by multiple triggers (push, pull, etc.). I've been trying to implement a movement system that allows for loops and twists and turns in a 2d space using velocity only but with no good results.
So far I've been applying a certain velocity based on maths every frame or so for X time (the time of the movement) but there's been 2 major problems:
It doesn't react well with the triggers (that pushes and pull) because my function Sets a velocity and doesn't modify the actual one with a new trajectory.
Its not smooth, every X time I can see the ball clearly changing trajectory which makes for an unrealistic and annoying experience.
Here's an image of what I'm trying to achieve:
Many thanks to anyone who tries to help.
You're not using physic stuff right ? You're updating the position in Update according to your var velocity ?
I'm not sure how you are representing your movement speed and direction, but assu$$anonymous$$g that you have a float movement speed and a vector representing the move direction, you might be able to get something like this by having your triggers set a target direction for the object, and then have the object rotate towards the target direction bit-by-bit over a number of frames. It will then appear as though the object is turning slowly in the direction he should go ins$$anonymous$$d of taking a sharp turn. Is that the problem you are having?
@$$anonymous$$romenak, I'll give your idea a try. I've also been thinking of using normalized vectors with sin and cos on the X and Y.
Answer by sparkzbarca · Nov 20, 2012 at 04:34 AM
there are kind of 2 ways to do this.
The easiest is probably to take the center point of the loop circle and rotate towards that constantly at a speed that is slower than the speed at which the object is traveling.
when its looking towards the right of the screen and the center is above it it will start rotating up. Now because its moving towards whatever side of the box is forward the front of the object will start rotating toward up so it will start arcing its way up. By the time it is facing straight up though the center of the circle will now be left of it and the process starts anew.
Get the speed right and the object will arc in a circle.