Trouble with local velocity

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

Hello everyone,
I have the ball on my stage and it keeps going forward. There are some checkpoints and I successfully change direction at these points. The problem starts right here after the change of direction. I can’t make left and right turns from the user after a change of direction. I am confused about what change i need to make where i marked with code

func _physics_process(delta):
velocity= direction* delta * max_speed*10
if translation.distance_to(points[current_point].translation) < 3:
	if current_point +1 == len(points):
		return
	else:
		current_point += 1
	rotate_y(-90)
	camera.rotate_y(-90)
	camera.offset=Vector3(-10,5,0)
	direction = (points[current_point].translation - translation).normalized()
if Input.is_action_pressed("ui_left"):
	velocity.x = lerp(velocity.x, -max_speed, 0.1)   ##### Here #####
	rotate_z(deg2rad(max_speed/5))
if Input.is_action_pressed("ui_right"):                   
	velocity.x = lerp(velocity.x, max_speed, 0.1)    ##### Here #####
	rotate_z(deg2rad(-max_speed/5))
if !is_on_floor():
	velocity.y -=  max_speed/12
move_and_slide(velocity)

Just an FYI, the delta parameter doesn’t have to be factored into the velocity when using the move_and_slide() function. Also, may I suggest doing the velocity calculation after adjusting the variable. For example:

#...
# Do all the velocity calculations above, then factor in the speed numbers below.
velocity= direction * max_speed * 10
move_and_slide(velocity)

Ertain | 2022-12-04 19:05

When I don’t use delta, the ball stays still and doesn’t move at all.
I did what you said about velocity.

Game_gulf | 2022-12-04 19:42

Then I don’t know what exactly the problem is, since the engine’s documentation says that delta doesn’t have to be included in the velocity calculation for move_and_slide(). Maybe it has something to do with the use of translations?

Ertain | 2022-12-04 20:03

it should not equal x while doing the rotation.

here:

if Input.is_action_pressed("ui_left"):
velocity.x = lerp(velocity.x, -max_speed, 0.1) 

Game_gulf | 2022-12-04 21:09