0 votes

Hello, i've been working alot on a tank game prototype, and it is going very well, but there is still a problem i'm not being able to fix, this problem is the tank turret rotation, i decided to use i diferrent approach to getting it done, so now i have a Spatial node that points in the direction of the hit location of a raycast that comes from the camera, and from there i rotate the turret of the tank in the Y axis and the gun of the tank in the X axis to match the rotation of this Spatial node (i know it is a bit hacky, probably, but it gives the best result of everything i tried).

here's the code:

var desired_rotation = turretG.global_transform.looking_at(cam.ray_pos, Vector3.UP)
var a = Quat(turretG.global_transform.basis.get_rotation_quat()).slerp(desired_rotation.basis.get_rotation_quat(), delta * turn_quant * turn_turret)
turretG.global_transform = Transform(a, turretG.global_transform.origin)

turret.rotation.y = turretG.rotation.y
maingun.rotation.x = turretG.rotation.x
maingun.rotation.x = clamp(maingun.rotation.x, deg2rad(depression), deg2rad(elevation))

my problem with it is that i can't keep its rotation consistent, it starts rotating fast and then it slows down when it is getting closer to its desired rotation, and gameplay wise that would not be fun to play with.

so is there a way i could make this rotation more consistent? any help would be appreciated.

Godot version 3.4.2.stable
in Engine by (99 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.