- Home /
Restrict a Players Movement Up a Slope
Alright, so I have slope detection working just fine, it returns the right angle I'm sitting at and everything, I just have one problem. I can do nothing about him moving up and down this slope, without him getting stuck or jittering to death. So my question is, how do I stop my player from heading up the slope, but make it so he can walk any other direction that isn't "up"? The main issue I'm having with this concept it he isn't actually moving up, the velocity just carries him up. I tried clamping his vertical movement axis to 0 and -1, but then he can just turn around and walk backwards up the hill. Didn't feel I needed to post any code, but if you need any let me know, I don't really need code in return either, just explaining a concept will suffice.
Answer by LSPressWorks · Aug 26, 2014 at 08:18 PM
Hmm, I had a very similar issue when using cobbler for TA. I tried everything I could think of, including using an invisible arm to check the angle and halting movement, which kind of worked.
That sort of method may work, as would an invisible wall.
There is a better way though. Since the first option requires checking the angle of teh arm anyway, I'd just use the angle of the character instead.Just get the difference of the angles like it shows here, and check that with an if statement before applying motion.
http://answers.unity3d.com/questions/244725/finding-the-relative-angle-between-two-gameobjects.html
Thanks for the link, as I said in the post I already have slope detection, meaning I already get the angle of the slope and the player, however in the comments in the link you showed there's one method that returns a positive and negative angles based on the players direction, this may just work. I'll test it out when I can.
Let me know I am actually kind of curious how it turns out. I loathe these sorts of issues, and have encountered them before. But it seems that unity has darn near everything already built in if one knows where to look.