Jump to content
  • Advertisement
Sign in to follow this  
Ultimate_Fusion

Character movement based on steering

This topic is 4222 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!