All Questions

Community

l

f-zero-like ships?

how should it be to implement an f-zero ship with rigid body?

  • GDQuestions replied

    In Node Essentials, you have a good example of a similar thing: a hoverboard. It uses a RigidBody for movement. You can find it in the RemoteTransform demos.

    See the script res://Screens/RemoteTransform/Skateboarding3D/Skateboard3D.gd.

    The general idea is to roll a ball that stays on the floor. It's a trick commonly used for arcade car controls. In our skateboard's case, the bulk of the movement is just those lines:

    var max_board_tilt := 8.0
    var max_speed := 36.0
    var turn_speed = 42.0
    var steering := 5.0

    func _physics_process(delta: float) -> void:
    var acceleration_input := Input.get_action_strength("move_up") - Input.get_action_strength("move_down")
    var rotation_input := Input.get_action_strength("move_left") - Input.get_action_strength("move_right")
    ball.add_central_force(-board.global_transform.basis.z * acceleration_input * max_speed)
    # tilt board to indicate turning
    tilt_axis.rotation_degrees.z = lerp(tilt_axis.rotation_degrees.z, rotation_input * max_board_tilt, delta * steering)

    We roll the ball and use the skateboard's orientation to get the forward direction (-board.global_transform.basis.z).  Let me know if you have any questions regarding this code or how it works. But using an invisible RigidBody ball that rolls on the road is a good starting point for a solid way to go about this.

  • l
    [email protected] replied

    thanks, i'll test it