Public Group

# object motion problem

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

## 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 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 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!

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633669
• Total Posts
3013258
×