Hey everyone. I’m new to Unity, but I have over 6 years experience programming in Flash, so I can understand Javascript pretty well.
One thing I’m not sure about though is how to do hit detection. I want to add in a wall jump that simply nudges the player left/right if they press jump while jumping next to a wall. Here is a crudely drawn explanation:
So if there is a wall to the players left, they will kick off to the right, and vice versa.
Any help I can get on this would be greatly appreciated!
Well if it stays in a 2d like fashion (like your image) you could use a raycast to tell if a wall is to your right or left. And then add a force to your rigidbody in the correct direction.
Edit;
Now that I think about it you could do it in a 3d environment too but it would be a bit more complex.
Sweet. I’ve looked a little in to raycasting I have successfully set up a raycast to poke out either side of the character and return a “hit” when you are next to an object. Unfortunately it only runs the script once for whichever side you hit first, even though it’s in Update(); , any ideas on this?
function Update () {
var right = transform.TransformDirection(Vector3.right);
var left = transform.TransformDirection(Vector3.left);
if(Physics.Raycast(transform.position, right, 1) || Physics.Raycast(transform.position, left, 1)){
Debug.Log("objHit");
}
}
Also, does FPcontroller have a state for the player? So I can tell if the player is jumping/walking/standing/etc. Or do I have to set one myself?