# How can I make the player slide when he does a 180 degree turn?

I'm making a roller skating game and I would like to player to skid or stop moving skating when they try to move in the opposite direction of their current one. But I'm not sure how to go about this.

I tried computing the the dot product of the input of the current frame and the last and if the product was less than or equal 0 that must mean the player did a 180 and the player's velocity was stopped. But it did not work, the product was always greater than 0,

• You need to cache the delta of direction (angle difference so to speak), check if it is greater than 180 or whatever you want, then play the skid animation/sound. You should write exactly where you got stuck so other members may give on-point answers. Commented Sep 27, 2017 at 14:20
• okay I added the method I tried to solve this problem Commented Sep 27, 2017 at 14:54
• "but it did not work." How did it not work? What did you expect and what did you get instead? What are you stuck with exactly? Is it detecting the sudden 180° turn? Commented Sep 27, 2017 at 15:37
• I expected it to stop moving when it detect the change. Commented Sep 27, 2017 at 16:27
• Make sure the velocity vector is normalzed before the dot product Commented Sep 28, 2017 at 5:58

The answer to this naturally will depend somewhat on your input method. However, there are some general principles.

The process of skidding occurs when one uses the skates to apply a great deal of force in the opposite direction from that of the skater's movement, and the skates break free. The key takeaway here is that this skidding process is a function of inertia.

The method you describe will tell you whether the input suddenly shifted 180 degrees, but that's not really what you want. What you want to do is determine if the input (which governs the forces the skater is applying) is in the same direction as the skater's momentum, or in the opposite direction. This will tell you if the skater is trying to speed up or slow down.

Depending on your input device, you may want to have a small region around this 180 degree point which causes a skid. It's impossible to reliably input exactly 180 degrees opposite something on most analog devices.

Thats how I would do it:

Having the velocity of the skater, I would detect if the player is trying to accelerate into the direction of a negative multiple of the velocity, hence in the opposite direction. If thats the case, the velocity of the skater should decrease by e.g. v*0,3 every second, so he should be able to skate into the different direction pretty quickly again. After the deceleration, he should start accelerating into the new direction again.

Maybe you want to play a scratching sound on turning and make his legs stop moving or have some sparks beneath his skaters.

Well, in Java, for example, you'd have a KeyListener check for your movements and IF... on a turn you faced the opposite direction of your velocity vector then it could trigger a stop response. Yeah... you'd have to listen for the left or right arrow keys and check for that and then trigger the stopMovement() response. Fact is... you know what would be easier? Detect turning and do a gradual vector decrease of movement to zero. This could all be done on KeyListener in Java very easily. But I see what you want, because a slight turn could slam you into a wall, right? But a 180 turn could eventually stop you in place. So you'd have to grab the turn degree and match it against the forward movement vector to react it into a gradual stop. Probably a wide range too. So it wouldn't need to be exactly 180 but somewhere within that range of degrees. Fact is, facing direction should equal resistance. In other words, if you're ice skating in a fast forward movement vector and you suddenly start to turn... then the vector should account for the turning resistance you just gave. So you'd add a different vector to the forward one to add into the turn... now then, if you turned completely the other way around... just check for a range for that, not 180 specifically but maybe 170-190 degrees opposite of forward vector and plug in HEAVY to a resistance variable for that vector movement.