0 votes

My tank turret acts weirdly when it has a high rotation speed and when it rotates full 360 degrees, it just stays stuck and doesnt move. Solution for that would be rotating the hull, but i still want to fix it anyway

extends KinematicBody

export var turretSpeed = 10

func _physics_process(delta):
var mouse_pos = get_viewport().get_mouse_position()

var origin = $Camroot/H/V/Camera.project_ray_origin(mouse_pos)
var target = origin + $Camroot/H/V/Camera.project_ray_normal(mouse_pos) * 10000

var new_transform_rot = $Turret.global_transform.looking_at(target, Vector3.UP)
var interpolated_rot = $Turret.global_transform.interpolate_with(new_transform_rot, turretSpeed * delta)
var direction = ($Turret.global_transform.basis.get_euler() - interpolated_rot.basis.get_euler()).sign()

$Turret.rotate_y(direction.y * turretSpeed * 0.1 * delta)
Godot version 3.4.2
in Engine by (12 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.