I am working on a game where players drive boats around. When two boats collide, they bounce off each other and push each other around based on velocity (this I have working).
I would also like to apply rotation/torque based on the force of the collision. The boats are CharacterBody3Ds, which I believe use rotation instead of torque (could be wrong). I detect collisions using move_and_collide, if that makes a difference.
My question is, does Godot already have a built-in method for calculating the rotational force applied from a collision? I can work it out the long way myself, but wanted to make sure there wasn’t already an out of the box solution before I reinvent the wheel. Thanks!
As far as I am aware it does not. However, as you implied, it should be relatively straight forward to detect the collision point and calculate torque from the normal and distance from centre and relative velocities. I say that, but these things have a habit of getting more complicated when you actually do it than when you just think about it abstractly
Sorry.
PS Your boat game sounds interesting. Any chance of a screen shot or is it too early?
You would have to convert to a RigidBody3D to get a physics API that has torque.
But since you are using a character class you just rotate on the y transform basis and apply some “angular friction” on rotation speed to slow it down. Or animate it. I would probably lock input and do an animation.
Thanks. I figured as much, but I’ve spent days working out something just to find out the engine actually handles it with one function or feature I was unaware of, so I figured I’d make sure.
The boat game is super alpha and part of my practice of making several small games that focus on specific aspects so I can better understand things. I wanted to try out split screen and I have not made a game in 3D before either. Attached is the ridiculously simple screenshot of the game in splitscreen mode.
I meant rotation but used the term torque in a general sense, forgetting it is literally called torque in RigidBody3D. Does CharacterBody3D have angular friction? I just lerp the turn speed to 0 to simulate friction.
No, that is why I put it in quotes, you would have to do your own physics simulation. Physics bodies do though. Your Lerp approach is adequate. Also a tween could work too.