@woopdeedoo said:
That snippet has a transform.TransformDirection, which "Transforms direction from local space to world space."
Do you know how to do that in Godot?
Transform
doesn't seem to have anything for that.
I can try! Here's a ported version:
func get_linear_velocity_at_point(rigid_body:RigidBody, local_point:Vector3):
# I think we can skip calculating P, as the local point won't be offset by the rigidbody center of mass since it's center of mass would be (0, 0, 0) relative to the local point
var v = rigid_body.angular_velocity.cross(local_point)
# I think we need to convert from local space to global space here, based on the code
v = rigid_body.global_transform.xform(v)
v += rigid_body.velocity
return v
I didn't test it, but it might work! That's at least how I would go about converting it using Godot's roughly equivalent functions. Then it should be able to be used something like this:
# get the local transform (transform) origin, which will be relative to the parent, which is the
# RigidBody we want to calculate with
var local_point = $RigidBody/point_with_offset.transform.origin
var local_point_velocity = get_linear_velocity_at_point($RigidBody, local_point)
print (local_point_velocity)
I think then it will work, assuming I converted it correctly.
It also makes use of the RigidBody.CenterOfMass. I don't think godot has support for that, but presumably I could just use the global_transform.origin
for that?
Yeah. In Godot the center of mass in a RigidBody is the origin of the RigidBody node, so global_transform.origin
is what you'd need.