Hello guys
Four days I trying to fix this problem but no luck so far...
So here is the problem: to understand what I talking about please check this video
- Blue wired box is collision shape
- white sphere represents where ray hits collision box
When I start game and ship not moving everything looks fine, where mouse button is pressed there appears white sphere but when ship starts moving white sphere appears not in same point where mouse is clicked, just look at the video at first looks fine, later looks like collision box getting smaller, probably miss calculations. in case here is my project
I know someone said something wrong with local and global positioning, but I cant figured out what or where is mistake. Here is raycast and rotation code:
func cast():
var mouse_pos = get_viewport().get_mouse_pos()
ray_from = cam.project_ray_origin(mouse_pos)
ray_to = ray_from + cam.project_ray_normal(mouse_pos) * ray_length
var directState = PhysicsServer.space_get_direct_state(cam.get_world().get_space())
var collisions = directState.intersect_ray(ray_from, ray_to, [self])
if collisions.size() and !collisions.empty() and collisions["collider"].get_name() == "nav":
col_pos = collisions.position
var t = get_node("ship").get_transform()
col = col_pos - t.origin
#print("collided with: ", collisions["collider"].get_name(), " distance ", ship.get_rotation().distance_to(col), " ___ ")
else:
print("something went wrong --> NO COLLISIONS DETECTED!")
func shipRotation(delta):
var t = get_node("ship").get_transform()
var rotA = get_node("ship").get_rotation()
var lookDir = col - t.origin
var rotTrans = t.looking_at(lookDir, Vector3(0,1,0))
var thisRot = Quat(t.basis).slerpni(rotTrans.basis, currentRotSp * delta)
if currentRotSp > global.shipRotSp:
currentRotSp = global.shipRotSp
get_node("ship").set_transform(Transform(thisRot, t.origin))
var rotB = get_node("ship").get_rotation()
if rotA == rotB:
enableRot = false
col = null

Please help me to fix this problem, because can't do anything till this problem exist.
Thank you!