How do you cast ray to the ground
by Nmuta Jones · in Torque Game Engine · 02/27/2010 (8:45 am) · 8 replies
I need to get the distance between the player and the ground beneath him, but I want to use script.
I would imagine I could just cast a ray from player to the ground. How do you do this in TGE ?
I would imagine I could just cast a ray from player to the ground. How do you do this in TGE ?
About the author
Lead Developer for MediaBreeze Multimedia
#2
%ray is not the position of the ray-collision. It is the id of the object found by the raycast. If %ray is zero then no object was hit.
02/27/2010 (11:17 am)
You should exclude the player from the raycast. %hitObject = containerRayCast(%startPosition, %endPosition, $TypeMasks, %id_of_the_player);
%ray is not the position of the ray-collision. It is the id of the object found by the raycast. If %ray is zero then no object was hit.
#3
02/27/2010 (12:08 pm)
you mean "include" the player? I excluded it in my example.
#4
I used the function with four parameters.
I excluded the player (the fourth parameter).
02/27/2010 (12:14 pm)
No, your containerRayCast has three parameters. I used the function with four parameters.
I excluded the player (the fourth parameter).
#5
I left out the last parameter.
02/27/2010 (12:17 pm)
I am using the English word "exclude" to mean "leave out". I left out the last parameter.
#6
02/27/2010 (12:56 pm)
Then you should include the fourth parameter to exclude the player from the ray.
#7
02/27/2010 (1:02 pm)
Oh, I see.... so the fourth parameter identifies what SHOULD BE excluded, so it doesn't hit my own player. got it. In this case, since I'm only targeting terrain, it doesn't hit my player, but that's a very good 'heads up' that you provided....thanks, I will definitely use the last parameter especially when I'm checking for "All Types".
#8
02/27/2010 (1:18 pm)
And don't forget: The return value is not a position. It is the ID of the hit object. Or zero if you did'nt hit a object with the ray.
Torque Owner Nmuta Jones
where my "down" vector is just the playerLocation with 10 subtracted from its z value.