Hi all. Just want a little help with my project.
I've got a turret that is fully capable of turning left and right. I'd like to impose a limit to how far to the left or right the turret may turn. The code below is my LazerGun.
extends KinematicBody2D
const LAZER = preload("res://player-side/EnergyShot.tscn")
const ROTATION_SPEED = 0.5
signal fire
var can_shoot = true
var rotation_Direction
func _ready():
pass
func get_input():
rotation_Direction = 0.0
if Input.is_action_pressed('test_up'):
rotation_Direction -= 1.0
elif Input.is_action_pressed('test_down'):
rotation_Direction += 1.0
if Input.is_action_just_pressed('test_fire'):
fire()
func fire():
var lazershot = LAZER.instance()
lazershot.start($LazerSpawn.global_position, rotation)
get_parent().add_child(lazershot)
func _physics_process(delta):
get_input()
rotation += rotation_Direction * ROTATION_SPEED * delta
func _on_FireRate_timeout():
can_shoot = true
I'd like to have a clamp() in there, but how do I limit the rotation to 45°/-45°?