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.

Dark GDK / Get distance from object?

Author
Message
Mister Fuzzy
13
Years of Service
User Offline
Joined: 27th Feb 2011
Location: XNA
Posted: 10th Jul 2011 04:35
Is there a way to get the distance value from an objects position and the surface of an object directly in front of it?

"C++ is hard..."

-Donald Knuth-
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 10th Jul 2011 05:11 Edited at: 10th Jul 2011 05:16
Well to find the distance between two points you can use this code:



However, because you want the distance from an object to the surface I think you have 2 viable options:

1. Cast a ray from the first object to the 2nd object using a per poly collision check and get the distance of the final ray. The distance may be conserved in the collision library of your choice, but if it's not you can use the distance formula above with the ray start and end position.

2. Mathematically find the surface (polygon) of the 2nd object that is facing the 1st object and find the center of that polygon. Then use the distance formula from the object to that center. This would definitely be harder to do, especially if you have models with inverted polygons and such.

I would say to use method 1 and use something like Sparky's collision or some other collision library.

"So hold your head up high and know. It's not the end of the road"
Switch Game Engine

Login to post a reply

Server time is: 2024-11-19 09:43:14
Your offset time is: 2024-11-19 09:43:14