I feel like this should be very simple, but I can't seem to figure it out. I want to get a point in front of the player vehicle for an eventual castRay(). I have the current user position gotten via getPosition(), and I attempted to get the rotation for use, but the vehicle rotation never changed. How would I go about getting a point that is always a set distance in front of the PlayerVehicle's front bumper?
This code will work only on GE side and obj is the vehicle object. It does a raycast from 5 to 20 m in front of the vehicle Code: local pos= vec3( obj:getPosition() ) local rot = quat( obj:getRotation() ) local zVec,yVec,xVec = rot *vec3(0,0,1), rot *vec3(0,1,0), rot *vec3(1,0,0) local p1 = yvec * 5 + pos local p2 = yvec * 20 + pos local distance = be:castRay(p1:toPoint3F(), p2:toPoint3F() ) Note : you may need to invert Y and X with 0.12 and after use the method below
Here is an updated version that is better to use in 0.12 Code: local pos= vec3( obj:getPosition() ) local zVec,yVec= vec3(obj:getDirectionVectorUp()),vec3(obj:getDirectionVector()) local p1 = yvec * 5 + pos local p2 = yvec * 20 + pos local distance = be:castRay(p1:toPoint3F(), p2:toPoint3F() )
That doesnt seem to work, the rot is always 0,0,0,1. So no matter where im facing it gets distance in only one direction. im getting the vehicle via be:getPlayerVehicle(0), am I supposed to use another method?