Page 1 of 1
Angular movement and another question
Posted: Wed Oct 20, 2010 8:54 pm
by StoveBacon
Ok, so I know basic movement (increasing an x and y and using that to draw whatever), but this only allows in 8 directions of movement. Whats the best way to move things in non straight or 45 degree angles (like move something in a parabola) aaaand i would like to know how to create multiple amounts of things(like in tetris how multiple blocks are created) and how to manage them automatically like collision detection)
k thanks :3
Re: Angular movement and another question
Posted: Wed Oct 20, 2010 9:21 pm
by dandymcgee
Say what? How does position limit your direction of movement at all? If either velocity is zero and the other is set it will move on the x or y plane respectively. If they are both equal it will move at a 45 degree angle, sure. But what if they x velocity and y velocity are different? You can set the velocities however you damn well please, nobody is forcing you to use straight lines.
For example let us assume:
x velocity = 3 pixel/second to the right
y velocity = 4 pixels/second up
Magnitude of movement would 5 pixels/second up and to the right following a line with slope 4/3. Decreasing the y velocity over time would cause an arc (and if done evenly a perfect parabola).
There are infinite number of ways to make an object move however you like, so think about this very simple example and see what you can come up with.
Re: Angular movement and another question
Posted: Wed Oct 20, 2010 9:48 pm
by davidthefat
Vectors:

Re: Angular movement and another question
Posted: Wed Oct 20, 2010 10:48 pm
by Ginto8
davidthefat wrote:Vectors:

aaah, fuck those polar notation vectors! Just go straight (x,y). Believe me, the amount of stuff you can do with vectors is amazing. Never leave home without a pocketful of vectors.
Re: Angular movement and another question
Posted: Fri Oct 22, 2010 2:33 am
by EccentricDuck
Why use vectors alone and wind up having an additional variable for rotation when you can use Quaternions!?

(this shows two quaternions)
But in all seriousness, it sounds like you're doing 2D so a 2-part vector would be simplest. A vector either holds an x and a y component (cartesian), or a magnitude* and rotation value (polar). Both have their own advantages. If position is x and y, and you have a "facing" or "forward" vector with x and y components, as well as some velocity amount (let's say 2 arbitrary units), then you could adjust position by going position.x += forward.x * 2 and position.y += forward.y * 2. That's pretty easy if "forward" is dependent on whatever key you press (like most old school 2D games). However, if you want to smoothly rotate then you need to store "rotation" and do what was shown above in the picture. In that case it's a toss up between polar and cartesian, depending upon how often you calculate rotations (more of this favors polar)/how often you calculate movement in the given direction (more of this favors cartesian).
*(this would just be 1 in most situation, unless you wanted to store velocity here as well but that's prone to rounding errors)
To manage collisions automatically, one way would be to have a collision detection class (let's call it CollisionManager) and add all objects that apply to a collection inside the class. From there, check for collisions from any "active" objects (things that are moving around, like a player controlled ship). You could check by calling a checkCollision() function that is in the CollisionManager (I use a singleton, which is basically a class that is somewhat static in the sense that you can't create objects of it, except for one object that is created and is accessible to other classes in a namespace - at least in C#).