0 votes

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)
Godot version 3.3.4
in Engine by (12 points)

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)

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

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?

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) 

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.