So I’m trying to make a skater type game like Tony Hawk’s Pro Skater. I know I’m going to run into tons of problems, because the logic/physics is already confusing me, but I like those kinds of challenges.
My current problem I believe is just my ignorance about how physics works. I want the character to change Y rotation ONLY by user input, and to change X rotation based on the ground under the skateboard (Z rotation should never change). In terms of physics, the character is currently a capsule rigidbody, which I think makes the most sense to be able to interact with physics, and be smooth (I’ll just make it invisible, and have a character mesh over it eventually). At this point I have made the capsule on it’s side forwards lengthwise, and I have locked the Y and Z rotations (so it should only rotate forwards and backwards, to interact with ramps). This way, it cannot tip over, and it will ride the ramps properly.
Problem 1:
My problem now is that the thing feels entirely uncontrollable. Any adding of force makes it rock around in a weird way. When I try to go forward it rocks and and forth like a teeter totter (although it does move forwards quite well).
Problem 2:
Rotation locks seem to be local or something, because I can quite easily mess up the character and it starts flipping out all crazy. I can watch the rotation in the inspector, and first of all, the Y and Z rotations are changing, when its locked, which is annoying. Also, the X rotation is the one that’s freaking out, making it roll all over like a sausage, but it shouldn’t be. It looks like the global X rotation is locked (maybe?) but because I’ve moved, the local X rotation is different, so now it can roll on its side? It seems as though any chance I give it to rotate, it will do something weird. Like if I place it on a ramp and leave it there, it will start rolling to the side, which is shouldn’t do, because the rotations are locked. It should only be able to rotate forwards and backwards right now, but for some reason it’s rotating on the Z axis.
How do I make the rotation locks actually lock properly? How do I lock global VS local rotations, and basically just make it so it will ONLY ever rotate forward and backward, locally.
Problem 3:
How do I change the forward force that I have to constantly be forward? So if I have a force of 20, and I rotate my character 45 degrees to the left, I now want the 20 force to be going in that direction. Hopefully that makes sense. Basically how the Tony Hawk game would be, where if you’re going fast and you hold left, your character turns to the left and continues their momentum.
Problem 4:
The rotating backwards and forwards feels bad too. Sometimes I slide up the ramp on my nose. The force just feels weird. If it’s a quarter pipe, I basically go up it without tilting, when I should be tilting. I’m guessing it’s because the force is forwards on the Z axis, rather than forwards relative to where my face is pointing.
This one makes the force go forwards on the Z wherever I’m pointing. (zMove is just pressing W or up on controller).
Vector3 V3Force = CharSpeed * transform.up * zMove;
rb.AddForce(V3Force);
I tried this one, which “kinda” makes the force go forwards where my nose is pointing
rb.AddRelativeForce(new Vector3(0, zMove, 0) * CharSpeed);
Problem 5:
Even just if I have a lot of speed going towards a quarter pipe, the character won’t even reach the top. It’s not tall, only like 6m tall or something, and the force just plummets the moment the character starts riding it. It goes up a little, but the force just dies. This isn’t really how things interact in physics, so I’m wondering how I can make it actually ride the ramp like things do in real life.