So i’m trying to figure out how to get my character to know that if he is jumping and the direction is towards a wall or is colliding with a wall to then hold onto the wall and slowly slide down for before falling off.
But if before slideTime is up and the user holds the opposite direction and jumps again he will launch in that direction.
So I am kind of new to both programming and Unity so I figured the best place for advice is the forums in hopes to not receiving troll like replies.
I’m not asking for the exact code(Unless you want to give it to me).
But more on snippets on how to get started.
The best way is to explain in steps but answer the way you want.
First figure out how to know your character is in the air by checking if he’s off the ground. You can do it by setting a var when the jump button is pressed, or something like:
if (transform.position.y > 1){
jumping = true;
}
Second, figure out if he’s touching a wall. For this you will probably have to apply a mesh collider or box collider on the walls and give them a tag of “wall” in the properties dialog. Then create a script that does something like this:
(pseudo code, this will not compile)
function OnCollisionEnter(collision : Collision) {
(if collision.tag = "wall"){
onWall = true;
//trigger sliding animation
}
This is not complete, but it should get you started.
Awesome thanks!
But what would be the best way to force the character in the other direction?
Can you apply a force to the character for a split second to get the effect as if you jumped off?
Any ideas?
I would suggest trying to do a simple Mathf.Lerp with the position which will move him in some direction.
Thanks for the help so far but I ran into an error.
It is telling me ‘tag’ is not a member of UnityEngine.Collision
That’s probably why.
Check the Unity scripting reference and search for “tag” it should steer you in the right direction.