Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Frozen8950

Slope Equation on a 2D Plane

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

Hey guys I have a question. I just feel dumb today lol because i cant figure this out and i know i have it on the tip of my tongue. Ok.. So i have a 2D Plane from (0,0) top left to (800,600) bottom right. i have a person that can move around on this plane and then I have an AI person that is supposed to move directly towards the other person. Ive been trying to achive this with a slope equation and if the AI is lower right to the regular person it works out ok.. but as soon as i run my guy in cirles around the AI it freaks out and does somthing its not supposed to do. It seems that i have to check and find out which side the person is on relitive to the AI before i do any calcuations? that doesnt seem right.. anyone done this before? anyone know how to do it? Thanks

Share this post


Link to post
Share on other sites
Advertisement
The direction of the AI''s movement (toward the person) is just a vector subtraction between the Person point and the AI point. But this is only direction. I don''t know how you''re moving the point.
Person<---------AI
Person at A=(x, y), AI at B=(x1, y1)
A-B = (x-x1, y-y1). So if your AI moves from his current point, in the A-B direction, he''s going straight to the person.

Share this post


Link to post
Share on other sites
The simple way is like this, lets say your program tells the direction of the enemy in 4 directions, represented by 1 north, 2 east, 3 south and 4 west.
You take the value of HeroX - EnemyX and see if its bigger than HeroY - EnemyY, if it is bigger, our direction most needed is X, so we figure out which direction we're going, either east or west by seeing if HeroX is less or greater than EnemyX.

Simple.

If I were working in slopes, I'd be moving into degrees, y=mx+b, so you've probably got a problem in your math, but I don't know, it might help if you elaborate.

[edited by - valles on June 1, 2004 12:13:28 AM]

Share this post


Link to post
Share on other sites
Take note of what quadrant your enemy is in vs. your hero. If you are in the quadrant I and e is in quadrant III then the slope you want will be positive. If you are in quadrant IV and e is in quadrant II, slope will be negetive.

[edited by - PhaseSpace on June 5, 2004 8:31:46 AM]

Share this post


Link to post
Share on other sites

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