The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

My current code is at the bottom, but here's a description of what I'm trying to accomplish:

I have a 3D RigidBody. When I yaw, I want to rotate it back and forth around the global Y axis. If it's not rotated at all, my current code works. Take a look at this gif: https://imgur.com/a/ypKzOc9

First, I yaw left and right. Then, I pitch up and down. It works correctly. Then, I yaw left, and pitch up, and it flips wildly end over end.

The behavior I want is this (demonstrated in editor): https://imgur.com/a/V3qmBaa

extends RigidBody

var yaw_force = 5
var pitch_force = 5

func _ready():
    pass

func _integrate_forces(state):  
    var yaw_axis = Vector3(0,1,0)
    var pitch_axis = Vector3(0,0,1)

    if Input.is_action_just_pressed("game_yaw_left"):
        state.apply_torque_impulse(yaw_force * yaw_axis)

    if Input.is_action_just_pressed("game_yaw_right"):
        state.apply_torque_impulse(-yaw_force * yaw_axis)

    if Input.is_action_just_pressed("game_pitch_up"):
        state.apply_torque_impulse(pitch_force * pitch_axis)

    if Input.is_action_just_pressed("game_pitch_down"):
        state.apply_torque_impulse(-pitch_force * pitch_axis)
in Engine by (17 points)

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.