- Home /
How would I make a character flatten against a wall?
I'm making a stealth game, and one of the features I want my game to have is the ability to flatten the character's body against a wall. This is what I mean:
This is a classic stealth game mechanic, but I'm not sure how to pull it off.
This is what I have done so far:
The white cube is a wall, the red cubes are invisible collision boxes, and the white cylinder is the character.
When the character enters one of the red collision boxes, a prompt appears onscreen (the shift key, for example). If the player presses that button, the character's rotational value becomes equal to the rotational value of the red cube. Each individual red cube will always be oriented to face away from the wall it's next to.
The basic functionality works, but this doesn't take into consideration things such as moving alongside the wall; the character should be able to crab-walk sideways along the wall when flattened up against it. Does anyone know what I'm talking about?
If anyone here could offer some advice on the best way to implement this feature, I would be extremely grateful!
well you'd just need animations of the character in that position or motion.
the one and only way, pretty much, to get character animations is "buy them from $$anonymous$$ixamo, like everyone else"
$$anonymous$$ixamo is totally integrated to the asset store, indeed at the moment they are having an incredibly cheap deal
Well, I went to college to take courses in 3D animation and I have an associate of arts degree in animation, so I think I can handle the animations myself; I've already made a few anims for this game.
The problem I'm facing is that I don't know how I should go about limiting my character's movement to "stick to the wall".
A huge range of skills use this site, from people who don't know what "if" is in code to professionals!
$$anonymous$$otion capture is normal for the FPS sort of genre, why I mentioned mixamo .......... if it's something you'd animate yourself all the better!!
So your problem is basically finding a line of points along the wall ..
I'm pretty sure the best way to do that is using raycasting. that's normally how you send out "feelers" for anything AI-ish to find surfaces etc
So that's probably the answer
(Obviously, there could be some special situations .. like if you know it's literally norht-south or something you could literally just change the Z value, or whatever .. but that's kind of special.)
Thirdly and also very simple --it's common in places like that to very simply drop in "line markers" So drop in two empty objects ("markers" if you will) that define the start and end of a line that one of your animated characters can crab along. Write a general routine that takes two such points and makes the character behave along those.
then you can just drop "units" like that (the two markers with the script) anywhere you want in the scene
Beyond that if you describe the details of the game more, I and I am sure others are more than happy to offer other possibiltiies
As a rule "raycasting" is how you do that.
An interesting point: in ordinary car games, that's literally exactly how the car stays on the ground, knows where the ground is. You just continually raycast to the ground surface, to see where the hell it is you know, and set the suspension appropriately.
You can see that your situation is essentially the same ... but it's the wall not the road!
So that's really "the" general solution. Rock on!
Your answer
![](https://koobas.hobune.stream/wayback/20220613083101im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character movement range in strategy game. 2 Answers
Why am I not moving forward? 1 Answer
Third Person type Rpg movement 0 Answers
Why is Character just moving "smooth" when camera follows? 0 Answers
Children must not flip with parent. 3 Answers