Godot Version
4.2.1
Question
Hello! I’m making a racing game in 3D and I want to detect when the car is falling. To make this car I made a Rigidbody with a Collision with the shape of a sphere, so the sphere rotates using the input. Something similar to this: https://youtu.be/LqLchhxMldM?list=PLubDg5W95PVB10DcrV0fYfas0i_RCygqY
I tried using: if linear_velocity.y < 0:
, but since the ball is rotating, the Y axis is not always pointing upwards. Any idea of how to do this?
Thanks
I think you may be looking for this;
Basis get_inverse_inertia_tensor ( ) const
Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the RigidBody3D.
But, I’m not really sure if falling is considered as inertia. This will definitely let know if the ball is rolling.
1 Like
You can also add a child to your RigidBody node, like always and just watch that location. Like a marker with locked location. Someone explained how a RemoteTransform3D works for me. But, I’m still trying to remember the real way this is done. It’s very similar. But, it’s used in composition with something like GeometryInstance3D in Godot. It has it’s own name in other languages(C/B/Progmm)
I just want to make a suggestion. Try to get records of how high the car can jump first.
1 Like
Thanks, but it didn’t work. As you said, it detected if the ball was rolling.
Thank you! Do you know how could I keep record of the marker’s position over time? I mean, how do I know the marker’s velocity?
There is no velocity in Godot. It’s a code variable. Basically Godot follows a predefined rule. A default square is 1 meters. I’m not really sure if it’s possible to change unit or scale. It’s not terrible, a normal 3D model values of 1x1x1 is just called 1x1x1 meters in Godot. You can get the basic idea. An avarage screen size is about 10 meters. And the visual angle is about 36 degrees. View distance is about that. Squared at 1000 meters. You would need to define your own converter for miles, kilometers or knots. But, the closest thing you’re going to come to in the code is simply. 1 meter a second. If you got questions about that. And, how to consult a tachymeter. I really suggest starting a new discussion.
The concept is not that hard to capture. You got your distance traveled in 3D space. This unit of distance is always constant to your code. And, this will be done in meters a second. If you create a stable converter code. Then the values appropriate for velocity and speed can be written down in the code as the converted values for Miles or Kilometers. You don’t have to value delta at any time. You can try it yourself.
extends Node2D
var mpr_speed = 34*2.23694
func _ready():
print(mpr_speed)
and there you go. 34 meters a second. with print output saying it’s going to be 76.05596 miles per hour.
Then the values are just displayed on screen as a speedometer. And, you can create a guage. To display the percentage of the gauge filled from minimum to the maximum.
I mean I don’t mean to confuse you. I got to confess I’m a little sick. In your case. Your questions are irrelevant. All the objects are positioned using matrices. On the XYZ. So, all the changes are also recorded there. Like here’s another example in 3D you can try it to.
extends Node3D
func _ready():
print($RigidBody3D.global_position.y)
print($RigidBody3D.position.y)
print($RigidBody3D.linear_velocity.y)
print($RigidBody3D.inertia.y)
Here’s several prints that only apply to the Y matrices. It’s true here. Because I manually moved the body.
- Global position on the current map.
- The last applied position of the object manipulation. Either self or the global map.
- Velocity, as pre-built in Godot according to the 1 meter scale.
- Inertia also as pre-built in Godot as 1 meter scale. Inertia is built to be dynamic.
This is basically the information you can see in the Transform properties.
And, for some reason what you manipulate.
1 Like
Ok, thank you so much for your replies. Sorry if I was a little too annoying 
Can I ask why you want to detect this?
Would detecting if it was in contact with the ground be as good?
Well. Okay. Try a snippet like this. This is strictly for demonstration purposes. It should not reflect practical application.
extends Node3D
func _process(delta):
if $RigidBody3D.linear_velocity.y < 0:
ring()
func ring():
print($RigidBody3D.linear_velocity.y)
I figured out several reasonable troubles while testing this myself. Linear velocity down is in negatives. Like -1. Henceforth; wilbert will want to see < than 0. And, linear velocity up is positive. So just regular code. 1 and > than 0.
I can even take it a step forward just for you. You can try it like that in code. Also, in the case #1,005,364. This happens more than often. As you can understand computer codes usually get the battered difference of 1 and -1. If you see something like this, you might get a permanent dissolution.
extends Node3D
func _process(delta):
if $RigidBody3D.linear_velocity.y < 0:
ring()
func ring():
print($RigidBody3D.linear_velocity.y*-1)
I mean I typically don’t want to step away from the previous comments. Because in rocket science this is called gamut and trend. Because you would want to create a similar environment variable like yours. But, you don’t want to loose sight on the roll of the ball. And, also you don’t want to loose sight on the position up. Something like your question but in retrospect to a machine direction up. Not to mention it gets a little complicated as far as placing a marker on the ground and just having the marker dictate the direction which is up.
Here’s an example of an architecture that will work in your game. Don’t get physics and the demonstrations of applied physics confused.
First more important. Is set the example markers. I got one saying where forawrd is. Another saying where up is going to be. I also added visual instances so I can see where they are in the editor. I also created a hierarchy of parts that will be applied. From here on don’t forget how the transform tools work. Because the children are going to be counted to be at zero from the origin center of the parent node. Why the hierarchy is important. Because if I wanted to apply code to this. Only the vehicle container and it’s contents will have to move forward and turn to make it look exciting. Other things, like bumping, breaking and falling down can be still successfully in the code from manipulating the vehicle body. Without the interference of the parent node, because it’s not going to get effected at all. As long as it’s not at astronomical scale. That way all the parts can be on the single screen.
You can keep track of changes to the global position of the object:
var previous_y_position : float
var falling : bool = false
func _ready():
previous_y_position = global_position.y
func _physics_process():
# do not swap these lines, the order is important
falling = global_position.y < previous_y_position
previous_y_position = global_position.y
Sorry for the late reply.
I want to make the car fly once it stopped rising. Something similar to the fly mechanic in Mario Kart
1 Like