A few questions regarding vehicle physics/Jolt #384
-
Is it possible to get vehicle physics similar to GTA using a VehicleConstraint or would a new constraint need to be made for fine tuning? I've noticed that sometimes the vehicle physics feels decent, and other times some things seem off about it. It is hard to say what exactly it is without experimenting more. Vehicles seem very easy to move. It makes me think I should be configuring something differently. If I make a player controller based off the CharacterTest in the Jolt samples of 80kg, I am easily able to push around a 1500kg vehicle. Even when coming at the side perpendicular to the vehicle's front. This is in a demo where the car's body has a friction of 1.0f as well as the floor having a friction of 1.0f. This is also a bit confusing to me personally since the friction is defined at the car body level instead of the wheel level. It also seems far too easy to push vehicles in a forward direction. Even if I have the handbrake/brake turned on, it still is easy to push it around with the 80kg character. When the handbrake is off, it feels like I am pushing around a toy car with how light it is if I am pushing it forward/backwards with the character. Any advice is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Games often use the "magic tire formula" because plain old friction isn't going to model the way tires interact with the ground. There's a nice tutorial here, https://asawicki.info/Mirror/Car%20Physics%20for%20Games/Car%20Physics%20for%20Games.html that goes into some detail about what you need to do to get a nice-driving car. |
Beta Was this translation helpful? Give feedback.
-
The body friction is not used for wheel friction. It is only used when you scrape the body of the car against a wall. The tire friction is defined in WheelSettingsWV::mLongitudinalFriction / mLateralFriction.
For the player I would recommend using a CharacterVirtual instead of a Character. CharacterVirtual allows you to specify how strong the character is (CharacterVirtualSettings::mMaxStrength default 100 N). If I add the car from VehicleConstraintTest to CharacterVirtualTest then I cannot push the car when the handbrakes are on, and only very slowly when the handbrakes are off. I would recommend the Character class only for AI or as an inner capsule for CharacterVirtual to allow it to collide with other CharacterVirtuals because it has less control. What happens if you use the Character class and set the velocity every frame (as happens in the CharacterTest::HandleInput) you will apply an impulse to the car every frame: P = mass * delta_velocity = force * delta_time, so: force = mass * delta_velocity / delta_time = 80 * 6 / (1 / 60) = 28800 N Note the 6 comes from cCharacterSpeed since I'm assuming that the car has reduced the character speed to zero after every time step and CharacterTest::HandleInput sets it to 6 again so all of the impulse is transferred to the car. So you see that the Character is very very strong because of this and can easily push away the car. You would need to control Character using forces instead of velocities to fix this, but that means the character accelerates much more slowly and is probably not good for gameplay. |
Beta Was this translation helpful? Give feedback.
The body friction is not used for wheel friction. It is only used when you scrape the body of the car against a wall. The tire friction is defined in WheelSettingsWV::mLongitudinalFriction / mLateralFriction.