• 13 Posts
  • 30 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle






















  • (Not op, just an example)

    I don’t know an optimal answer here. I see various discussions online about flight control variants. However, here is a simple example I set up out of curiosity. Maybe useful? I’d like to hear about what you end up with.

    Project code at: https://github.com/pipehat/godot41_flight_controller_example

    ————————————

    plane controller script:

    
    extends CharacterBody3D
    
    var print_delay = 1
    var next_print = 0
    const SPEED_MPS = 500
    
    func _physics_process(delta):
    	var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    	
    	if next_print <= 0:
    		print(input_dir)
    		print("-z: ", -transform.basis.z)
    		next_print = print_delay
    	else:
    		next_print -= delta
    	
    	var roll = -input_dir[0]
    	var pitch = input_dir[1]
    	
    	rotate(transform.basis.z, roll * delta)
    	rotate(transform.basis.x, pitch  * delta)
    
    	velocity = -transform.basis.z * SPEED_MPS * delta
    	move_and_slide()