#A few problems with my ship movement

2 messages · Page 1 of 1 (latest)

near peak
#

My Script:

extends CharacterBody3D

const MAXSPEED = 30

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    rotate_z(0)
        
        
        
func _input(event):
    if event is InputEventMouseMotion:
        rotate(Vector3.UP, event.relative.x * 0.001)
        rotate(Vector3.RIGHT, event.relative.y * -0.001)

        
func _physics_process(delta):
        rotation.z = clamp(rotation.z, 0, 0)
        var forward_direction = Vector3.FORWARD  # Global forward vector
        var movement_speed = -25 
        translate(forward_direction * movement_speed * delta)
  1. When I go backwards my ship movement inverts
  2. I got a clamp for the z rotation to stop it from turning over but when going to a certain rotation it just breaks and goes crazy
    What could I do to fix those problems?
hasty eagle
#

To fix the first thing, try using translate_object_local instead of translate.
For the second one, try using rotate_object_local instead of rotate