Sign in to follow this  

object motion problem

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The movement of my objects is defined by 2 varibles, speed and direction. Speed is the number of units the object moves every step and direction is the direction it moves in degrees (with 0 being to the right and 90 being up etc). I want to be able to effect this movement in a number of simple way. I'm not bothered about simulating mass at this point so I just need a simple function to change the objects speed and direction) motion_add(force_dir, force_speed); so if I have an object with speed = 10 and direction = 0, and I add speed = 5, dir = 180. The new objects speed and direction should be 5 and 0; Not sure I describe that to well so heres a table of examples...
Speed	Direction	Force_speed	Force_dir	new speed	new direction
10	0		5		180		5		0
10	0		15		180		5		180
5	0		3		0		8		0

Share this post


Link to post
Share on other sites
Use sin and cos to convert the direction/magnitude vectors to x/y vectors. Add the components. Use Pythagorean theorem and inverse tangent to convert x/y back to direction magnitude.

Share this post


Link to post
Share on other sites
Vector maths. Matrix maths, euler rotation. It really does make these things far more simple and flexible, after a small overhead of learning it. eg:


int GetDistanceBetweenCharacters(Character c1, Character c2)
{
return (c2.getPosition() - c2.getPosition()).GetLength();
}

void RotateCharactersDirection(character & c, float x, float y)
{
matrix33 m;
m.SetEuler(x,y,0);
c.SetDirection(c.GetDirection() * m);
c.SetRotation(m);
}

Character::Move(vector3 direction)
{
position += direction * rotationMatrix;
}

Character::Sidestep(float distance)
{
vector3 direction(distance,0,0);
Move(direction);
}

Character::Walk(float distance)
{
vector3 direction(0,distance,0);
Move(direction);
}








All the maths is handled by the vector and matrix classes. If you want to go into game development you will eventually need to learn vector / matrix maths, if you didn't already. You will love the simplicity, once you learn it all!

Share this post


Link to post
Share on other sites

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this