I am engaged on a raycast-based automobile in a 3D world utilizing a physics engine. It is mainly a chassis object that incorporates a remodel (translation, rotation, scale), a dynamic inflexible physique (with mass, middle of mass and different stuff from the physics engine) and 4 wheel youngsters.
Every wheel has its personal remodel, positioned the place the automobile suspension could be hooked up. It additionally defines suspension properties resembling radius, spring fixed, damper stiffness, and so forth.
Suppose I accurately calculate the spring power magnitude (the basic spring_force_magnitude = length_offset * spring_constant - spring_velocity * damper_stiffness
). Now I would like to use the power as a vector with the proper path. Additionally, overlook about different forces resembling acceleration or steering, I am simply making an attempt to mannequin suspensions right here.
Here’s a diagram that enables to elucidate my difficulty. The automotive is inclined and the bottom is a slope. Solely 2 (and even 1) wheel is involved with the bottom. It is a aspect or entrance view (does not matter) however suppose it is in 3D.
So there are the world up (international Y
), the automotive (or wheel) up and the raycast hit (the bottom) regular.
Most tutorials (like the favored Very Very Valet video) use the automotive up vector. It appears logical since that is how the suspension spring is oriented. However once I use it and the automotive is inclined, it will get a power pushing it to the aspect. After I use the conventional (like, I feel, the DigitalRune automobile) it appears to be too sturdy: the automotive jumps out as a result of solely 2 wheels are involved. Ought to there be an element that reduces the energy in keeping with some kind of (which?) angle?
The query is: which path? Automobile up, world up, floor regular, or a mixture of these?
I take advantage of Rust with the Bevy engine and the bevy_xpbd physics engine however I do not thoughts any code that targets Unity, Godot or others.