Jump to content

Basic x y z movement where to start from ? Logical question


namedrisk
 Share

Recommended Posts

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

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:

Posted Image

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
Link to comment
Share on other sites

wow i really appreacited that you took the time to help me out with this nice explannation :D

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

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:

Posted Image

Then the formula from the angle (SOHCAHTOA method) can be calculated using the opposite (ydiff) and the adjacent (xdiff).

Tan(angle) = Opposite/Adjacent

Or:

Angle = ATan(ydiff / xdiff)

: )

And we have our angle.

Link to comment
Share on other sites

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 :D

the images you posted and took the time to make made it so easy one me to understand

Edited by namedrisk
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...