How do I use slerp correctly.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dragon20C

I am currently trying to use slerp but godot complains about it not being a normalized vector, the error is exactly this (set_axis_angle: The axis Vector3 must be normalized)

I tried adding normalize to everything it complains, nothing changes.

code down below:

extends Spatial

var current_rotation = Vector3()
var target_rotation = Vector3()

export (float) var recoil_X
export (float) var recoil_Y
export (float) var recoil_Z

export (float) var snappiness
export (float) var return_speed

func _physics_process(delta):
	target_rotation = lerp(target_rotation,Vector3.ZERO,return_speed * delta)
	current_rotation = current_rotation.slerp(target_rotation,snappiness * delta)
	if Input.is_action_just_pressed("B"):
	set_rotation_degrees(target_rotation)  # I think this sets the rotation

func recoil_fire():
	target_rotation += Vector3(recoil_X,rand_range(-recoil_Y,recoil_Y),rand_range(-recoil_Z,recoil_Z))
:bust_in_silhouette: Reply From: S4_Yuuki

I think slerp needs two vectors to be able to run. At least, it’s what the documentation says, or I’m interpreting wrong… And both vectors must be normalized().

I didn’t used slerp yet, only lerp. So I can’t tell you what it exactly does or how you can write…

:bust_in_silhouette: Reply From: yrtv

From Vector3.slerp()

Note: Both vectors must be normalized.

Normalize vectors with Vector3.normalized()

I followed a unity tutorial and they used slerp as well and they didn’t need to normalise the vectors, actually normalising the vectors makes what I want it to do completely wrong, but thanks for answering anyways

Dragon20C | 2022-02-08 22:12