0 votes

I have used Godot for over a year at this point. It's my favorite engine and I'm eagerly waiting for Godot 4 like most!

My issue is that I'm trying to get linear_velocity in a RigidBody3D, and get the local z component of that. Without it being local, the z component will not represent the forward force. I just want to get the forward force of the rigidbody. In Godot 3.X, we'd use transform.basis.xform_inv(linear_velocty), but it appears this method has been removed entirely from Basis in Godot 4. Here is my code:

extends RigidBody3D

var real_speed : float = 0

func set_inputs(vertical : float, horizontal : float):
    pass

func _physics_process(delta):
    linear_velocity = transform.basis.z * -20
    rotate_y(0.02)

func _integrate_forces(state):
    real_speed = linear_velocity.z
    print_debug(real_speed)

Is there a method that I don't know about in the new API? Thanks in advance!

Edit: There seems to be a Transform2D method for basis_xform() and basis_xform_inv(). I wonder why a 3D version doesn't exist...

Second Edit: Hmm. In the Transform3D header file, there is an implementation of this method. So why isn't it in GDScript?

Screenshot of tranform_3d.h in Godot source code

Godot version 4.0.dev (daily nightly build from Calinou)
in Engine by (113 points)
edited by

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 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 webmaster@godotengine.org with your username.