Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Cordinate displacement

Author
Message
Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 20th Oct 2010 05:53
I want to displace an object towards a specific cordinate, please do not respond with the camand point object. I want to change the x,y and z values using only math.
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 20th Oct 2010 06:15
To linearly interpolate toward a position:

f = a + (b - a) * d

where f is the final position vector, a is the current vector, b is the target vector and d is the interpolation scalar in the range of [0..1].

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 20th Oct 2010 06:35 Edited at: 20th Oct 2010 06:36
If your specific coordinate is "static", that is, it doesn't move, then dark coder's example is going to be your best bet.

It gets a bit more tricky if you want your point to be able to move around, however. Like, for example, if you want monsters that chase a player through 3D space. In that case, you have to get the angle differences of your two points in 3D space, and then use trig to move your object towards its target.

For 3D space, you'll have 2 angles that are required to point in the direction of your movement vector - The Y angle (which is your rotation in the XZ plane) and the X angle (rotation in the YZ plane). Use the atanfull() function to get these angles, like such:

yAng# = atanfull((x position of moving object) - (x position of target), (z position of moving object) - (z position of target))

xAng# = atanfull((y position of moving object) - (y position of target), (2D distance between points on XZ plane))


where the 2D distance between points on the XZ plane is found using your standard distance formula.

Once you have these angles, it's a simple matter of using your SIN() and COS() functions to find the new position of your object. Again, it's a bit more tricky in 3D because you have two angles to worry about, instead of just one, but it's pretty easily solved:

* Increment objectX# by sin(yAng#)*cos(xAng#)*movementSpeed#
* Decrement objectY# by sin(xAng#)*movementSpeed#
* Increment objectZ# by cos(yAng#)*cos(xAng#)*movementSpeed#


And here's a quick example I put together for this. Use mouselook and click to move the camera, and press Space to reposition the objects. The sphere in this example acts as your moving object while the cube acts as the target point.




Although again, this is just if you want your "target point" to move - If it's static, then go with simple interpolation.
Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 20th Oct 2010 06:58
Thank you for your quick response's

Login to post a reply

Server time is: 2026-07-22 03:51:40
Your offset time is: 2026-07-22 03:51:40