# Character movement based on steering

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

## Recommended Posts

I am trying to make a character move to a point based on a sterring behaviour. i originally used magnitude = sqrt ((dx*dx) + (dy*dy)); to move in a straight line to the target. But I want to use add forces to the acceleration to move to which ever target is strongest. I used the code below to go to one target but it slightly circled the target before reaching it and was vibrating on the stop. I need this type of circle movement but not when there is only one target to move thanks tha
 long double dx = moveToPosX - rcSprite.x+48;
long double dy = moveToPosY - rcSprite.y+48;
long double magnitude = sqrt ((dx*dx) + (dy*dy));
long double stepY = (dy/(magnitude*0.1));
long double stepX = (dx/(magnitude*0.1));

float maxforce = 10;    // Maximum steering force
float maxspeed = 10;    // Maximum speed
float mass = 1;
float velocity=0;
float acc =1;
float steering_force;

steering_force = stepX;
//Acceleration = Force/Mass
acc = steering_force / mass;

//update velocity
velocity += acc;

//make sure vehicle does not exceed maximum velocity
// velocity.Truncate(maxspeed);

//update the position
rcSprite.x += velocity;

steering_force = stepY;
acc = steering_force / mass;
velocity += acc ;
rcSprite.y += velocity;

[Edited by - LessBread on January 28, 2007 2:27:59 PM]

##### Share on other sites
If you want to make the character slow down to a stop before reaching the target then after it gets closer than a min distance to the target multiply the speed by a factor of D/T where D is the distance and T is some number >1 that you can play around with to get the behavior you want.

##### Share on other sites
Have you had a look at Steering Behaviors For Autonomous Characters by Craig Reynolds? I used this paper as a basis for some character steering simulations for an animations course and the techniques worked beautifully. It's pretty much applied dynamics and control theory but presented in a very easy-to-use way.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011467
• ### Who's Online (See full list)

There are no registered users currently online

×