DAShoe1 / Godot-Easy-Vehicle-Physics

A ray cast based vehicle for Godot 4.0
MIT License
114 stars 6 forks source link

Motorcycles #6

Closed mattogodoy closed 4 months ago

mattogodoy commented 4 months ago

Hi there!

Thanks a lot for making this available. It's a great plugin with a lot of details! I really like it. This is not really an issue, but I wanted to ask: Is there a possibility to use this to create a motorcycle? I was thinking about something like a dirtbike. I've tried before, but I'm not very knowledgeable in game physics, and I found it quite difficult. I'd like to know if you have any ideas on how to implement this.

Thanks again!

DAShoe1 commented 4 months ago

While I think it would be possible to do motorcycles, I imagine most games involving motorcycles don't physically simulate keeping the bike upright. I played around with this a bit and here are my recommendations if you want to use my plugin:

  1. The plugin requires 4 wheels on the vehicle to function. I would just move the front and rear wheels inward so they are right next to each other, but not exactly in the same position. I tested with them 0.1 units apart. Then just remove or hide the left or right set of wheel meshes.
  2. Set the center_of_gravity_height_offset under Suspension low enough that the center of gravity is below the ground. Something around -0.4 to -0.5 seemed to work well for me. This is a bit of cheating that will make the vehicle lean into the turn instead of out.
  3. To keep is from falling over completely there is a stability setting stability_upright_spring that applies a force to keep the vehicle upright, although it only functions if at least 2 wheels are off the ground. You could modify line 922, https://github.com/DAShoe1/Godot-Easy-Vehicle-Physics/blob/73d9139597081d0d6cba392db7247f58a8d35b90/addons/gevp/scripts/vehicle.gd#L922 from < 3 to < 5 to have it always function, then increase the stability_upright_spring value to something like 10.
  4. Lastly you will need to lower the max_steering_angle to something like 0.2 or 0.3 and lower the steering_speed.

I think this will give you something that resembles a motorcycle, although I'm sure a lot of tweaking will be needed. It would probably be necessary to write some code to apply torque to the rigidbody when turning so you don't need to rely on an unrealistic center of gravity which can cause other issues.

mattogodoy commented 4 months ago

Thanks a lot for your prompt and detailed response! This is a good start. I'll give it a try. I really appreciate it 😃

mattogodoy commented 4 months ago

Closing as it is not a real issue.