How do I add forward force to an object so that when it rotates, it still goes forward relative to the object, not the world? (picture inside in case I worded it badly)
Does this make sense? Is it even possible? Sorry if this has already been asked, I don't know what to search to find this
That doesn't quite work, sadly. If I rotate while moving, then the board keeps moving sideways, like in the picture. Then, if I add force again, it is in a see$$anonymous$$gly random direction! What do
Answer by Statement · Oct 25, 2015 at 01:42 AM
Okay, so you want to model a skateboard. Skateboards have wheels. Perhaps you should look into Wheel Collider, as this will most likely simplify a lot for you. This should most likely be your first attempt on making wheel physics.
If you want to do the physics yourself, you can. I am not a physics math expert but I can let you pick my brain for ideas and try stuff out. Below is my own approach on solving the problem.
So, I am not a skateboarder myself and I don't know how forces are distributed when it comes to turning. But I can give you an example of how I understand wheels to work on cars (and mind you, this may be incorrect but I am trying my best here). The wheels on cars turn and rotate (or spin). The driver doesn't "add a force to the center" or "rotate around the center" of the car when they want to accelerate or turn. The forces are applied at the wheels.
Imagine a car is driving forward and then turns. No acceleration is applied during this example.
As the wheels turn, their axle will no longer be in line with the cars momentum vector (pink). As a result, the wheels will experience resistance forces (red) opposite to the momentum vector and experience greater grip depending on the angle between the momentum and the axle. The wheel itself has angular momentum (around the axle, blue arrow shows wheel top direction) and is in contact with the surface.
Forces are applied to the rigidbody, at the wheels,
I made an example which model a car with wheels in 2D. Each wheel act on the rigidbody. Turning the wheels implicitly rotates the car due to the traction forces (I dont know if it's called traction usually, but that's what I call it - grip, whatever).
I'll get back to this answer tomorrow and try to elaborate on how you can get car-like or skateboard-like behavior if you haven't got an answer that solves your question.
In the end, the behavior is what matters, not the phrases you used to describe it. I got too hang up on it and didn't consider what it was going to be used for when I wrote the answer.
What do you mean by traction control? Like, make one side of the board more friction-y than the other so that it turns?
Yes, kinda. But ins$$anonymous$$d of just applying friction against the momentum vector, you scale it with the dot of the wheels angle. So if the wheel is at an angle to the momentum vector, it will start applying traction (or friction) to try and steer it toward the momentum vector. Play the example, drag the sliders, arrow keys drive car. Then look at the source code.
Note: You could just grab the math from ApplyTraction
to customize your existing solution. In that case you can think of your entire skateboard being one wheel.
Your answer
Follow this Question
Related Questions
How To Rotate Player with Rotating object 0 Answers
Instant rotation bug when rotating clockwise 0 Answers
Access 2DCollision Torque/rotation force and set it to 0 0 Answers
Rotate 2D pivot so that gun points at target. 0 Answers
Torque applies to one wheel, but inconsistently to the other wheel 0 Answers