Hello - I’m making a skateboarding game using a rigidbody controller and I’ve made a lot of good progress, but I’m stumped on how to approach ‘switching’.
If you aren’t aware, this is when you keep the same velocity but switch your body and board position 180 degrees. If you start with your left foot at the front, body facing right, after switching you end up with your right foot at the front, body facing left.
Obviously I could simply animate this for cases where we are skating on the ground, but it wouldn’t work for ramps:
In the Tony Hawk’s games, if you move directly up a half pipe without any turn input, you will then fall directly ‘backwards’ and immediately be in a switched state, to then move around as usual, not inverted or anything. Any ideas on how I could implement this? Currently my character just reorients himself quickly upon landing to face the movement direction. Thanks
Thanks for the reply, but I think you are misunderstanding what I’m asking. If a player moves up a ramp, then without input, allows gravity to take effect and drag them back down the exact same way, the character should then be travelling in a ‘new’ forward orientation and the camera should reposition behind them.
if the force of gravity is greater than the velocity of the player going upwards, either initiate a switch, or keep the player forward and they can just roll backwards. not sure exactly how skating switch would change the actual gameplay, but i would assume it’s more of a visual change than an actual gameplay change. if this is indeed all that’s required, play some form of switching animation and keep track of whether you switched or not to modify the score the player got by switch #, landing switch etc.
if that isn’t your cup of tea, you can use vector3.dot to compare player’s forward direction and input direction to determine if they actually want to switch, making it more skill based as opposed to something more governed by physics.
this could also allow the player to initiate a switch by choice, simply by moving in the opposite direction they’re going, which would make for some cool trick combinations.
i’d love to see your laser flips later on down the line.
Thanks for the reply! Well, the ideal situation (and the way it is done in most games) is that you can press a button to switch at any time, which I think would be a pretty easy issue to get around, just play the switch animation as you say.
The issue comes with the example I’m trying to illustrate with the ramp. The direction of movement will change, but there can be no animation played, as we aren’t actually changing anything about the character - they are simply moving up a ramp, (facing left) then letting gravity pull them backwards, and then they are facing right (since it is the camera which has now moved ‘behind’ them).
I’m guessing I need to somehow define a new transform.forward or something? Do you have any tips on how I could do that? Let me know if Im not being clear.
i’m confused by exactly what case you’re talking about, the going left kind of threw me off. i thought you meant a player going straight up a ramp and being taken back the way they came due to gravity. maybe you could sketch something for me? it doesn’t need to be detailed.
as for switching transform, you can set transform.forward through c#, which i didn’t know for a while. it’s as simple as just doing something like
//this is pseudocode, i haven't actually tested this, but apart from var names, it should work.
//store flipped forward vector
Vector3 flipDir = -transform.forward;
//unflip the y vector so as to not make things upside down
flipDir.y *= -1;
//apply the new forward direction
transform.forward = flipDir;
you may also want to selectively flip only one axis or even (s)lerp it for smoother flipping, but this is up to how you want to implement it. if you only need to flip one axis, i believe it can be done in one line by just flipping it directly at the transform.foward’s x or z.
Hmm - I’m going to try implementing your pseudocode tomorrow- thanks! I’ve tried to illustrate the situation with the ramp here:
in cases like this, you should be able to use the same type of check with the gravity and velocity i mentioned earlier, but don’t play a switch animation and instead only perform the forward dir switching and move your camera however you like. your system should also be able to handle animating the switch from arbitrary directions though this could likely be handled with animation tree transitions.
you’ll probably want to use vector3.dot to determine if the player is facing the direction of gravity or opposite it.
vector3.ProjectOnPlane may also be of use when making this check, so as to check the direction the ramp is making the player face instead of just the player’s direction.