namedrisk Posted September 18, 2009 Share Posted September 18, 2009 Hi, i am making an AI to walk around and such and i have 2 types of information, i have the current location X, Y and Z and the camera view X, Y and Z and it did like some help about how would i create a movement based on that... For example i have waypoint A and waypoint B and would like to move from A to B so lets say: A = X: 2000,10 Y: 1200,01 Z: 150,00 B = X: 2800,25 Y: 1001,12 Z: 150,00 so i know i could check for x lower then and just move forward and Y lower and move to side YX in order to increase it or side YY decrease it... but is this the best way ? how would i work out if i am looking on the right direction ? make a first check like step forward and see if X increase or decrease ? Any advices on this would be appreciated i will see if i can post something on this as i didnt went out of the logical strategy yet. Link to comment Share on other sites More sharing options...
jvanegmond Posted September 18, 2009 Share Posted September 18, 2009 You left a lot of details for guessing ...Like, you say you want to create a movement based on two points, but what do you base it on? Do you just want to move from the current players position to the cameras position or do you want a movement like so:Because makes much more sense to me.Another thing, how do you move the player? Do you rotate it to face the right direction and then do a step forward or can you just set absolute X, Y and Z?The problem you are describing is simple math. Take one problem at a time:Say for X:From = 2000 To = 2800 MaxStep = 10 While 1 Diff = To - From If (Diff > MaxStep ) Then Diff = MaxStep From += Diff Wend github.com/jvanegmond Link to comment Share on other sites More sharing options...
namedrisk Posted September 18, 2009 Author Share Posted September 18, 2009 wow i really appreacited that you took the time to help me out with this nice explannation welli don't quiet get it myself i have a way to figure out my current position and get the X Y Z from it and then i want to creat an waypoint thing ... from one said to record the walking path it seems quiet easy as i could make the code record the x y z every X seconds or every Key hit to record the position this way i wouldnt have trouble with obstacle and such... but what i find trouble some is how i would know where i am facing to, to know where to start walking to... so one way of doing it would be the camera view as it reflect where i am facing i mean what side i am facing but i dont really know how to calculate it from the currenct position i am to figure what rotation should i be doing... Yes it is purelly math here hehe... and i am really bad at it ... but it is never late to learn i hope... based on what you posted i could probably do While 1 If (currentX < destinationX ) Then send walk button EndIf Wend but like i said my main concern would be if i am facing the right direction... once again thanks a lot i will be making something rihgt now to test the walking stuff and then post back my findings Link to comment Share on other sites More sharing options...
jvanegmond Posted September 18, 2009 Share Posted September 18, 2009 I hope you have learned this, but the determine the angle the player when you have only player pos and camera pos you can do this:Then the formula from the angle (SOHCAHTOA method) can be calculated using the opposite (ydiff) and the adjacent (xdiff).Tan(angle) = Opposite/AdjacentOr:Angle = ATan(ydiff / xdiff): )And we have our angle. github.com/jvanegmond Link to comment Share on other sites More sharing options...
jvanegmond Posted September 18, 2009 Share Posted September 18, 2009 I noticed I made a mistake in the image. ydiff = playery - cameray and xdiff = playerx - camerax github.com/jvanegmond Link to comment Share on other sites More sharing options...
namedrisk Posted September 18, 2009 Author Share Posted September 18, 2009 (edited) wow awesome man ... i was working on the waypoint write system and i was about to start the walking method but with what you posted now it made it real simple ... i really appreciate your help... i will post back my code as i get it done or with more question once again thanks for the effort the images you posted and took the time to make made it so easy one me to understand Edited September 18, 2009 by namedrisk Link to comment Share on other sites More sharing options...
jvanegmond Posted September 18, 2009 Share Posted September 18, 2009 That's great. Glad i could help. I have written the logic behind game NPCs before, and this is always the logic that I used. I had a nice post on the AutoIt forums about it.. I'll see if I can find it. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now