Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | swipis | |
Old Version | Published before Godot 3 was released. |
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!
I think that you will increase a chance that somebody will help you if you make your code more readable with proper formating. Read How to use Q&A and how to write underscore
lukas | 2016-04-12 14:38
thanks for the tip
swipis | 2016-04-12 14:54
Did this ever get fixed? The project link leads to a 404…
ericdl | 2016-06-10 03:46