Topic was automatically imported from the old Question2Answer platform.
Asked By
The Benjameister
I am creating a 3d Isometric platformer where the gimmick is that you need to rotate the camera to navigate the game properly. My camera node is comprised of two parts, a Camera Pivot and the camera itself.
I have a basic version of the turning already made, when the player presses the camera turn right button for example, rotation_degrees.y += 90 is called, rotating the camera 90 degrees as intended. Full code here :
extends Spatial
func _process(delta):
if Input.is_action_just_pressed("camRotateRight"):
rotation_degrees.y += 90
if Input.is_action_just_pressed("camRotateLeft"):
rotation_degrees.y -= 90
The issue is that this rotation is instant, and I want a smoother rotation. I’ve tried the following (still for the rotation to the right example) but it doesn’t work : rotation.y = lerp_angle(rotation.y, rotation.y + (PI/2), 1)
Instead of rotating between the two angles, it instead instantly rotates to a smaller angle (0 to 15 degrees instead of 0 to 90).
Does anyone know what’s going on here and how I could fix this? Thank you!
You didn’t say much but I’ve understood everything
The problem is you’re trying to rotate camera in _input function. But lerp_angle() not rotates angle but return a interpolated value of it. For smooth rotation you need to do it from _process function. Like this:
Unfortunately this isn’t what I’m looking for. This is a constant rotation. I want to make it such that if I press the button once, the camera is rotated by 90 degrees and stays at that new angle, hence the rotation_degrees += 90 I already have this in my _process() function. Here is my exact code :
extends Spatial
func _process(delta):
if Input.is_action_just_pressed("camRotateRight"):
rotation_degrees.y += 90
if Input.is_action_just_pressed("camRotateLeft"):
rotation_degrees.y -= 90
The Benjameister | 2022-07-31 12:00
Oh. Okay, sorry. Here’s solution:
extends Spatial
var target_rotation = 0 #Initial rotation
func _process(delta):
if Input.is_action_just_pressed("camRotateRight"):
target_rotation += PI/2
if Input.is_action_just_pressed("camRotateLeft"):
target_rotation -= PI/2
rotation.y = lerp_angle(rotation.y, target_rotation, 0.5)