Okay, so here’s the deal. I want to create some wall running scripts. The way I want to go about it is to have a trigger cube parented to my fps controller in the front, and one on each side. If the front cube collides with a trigger object with the tag of “wall”
then the player moves up. If the side cubes collide with the “wall” then run forward. The side triggers and code aren’t here yet because i have a problem. The collision seems to be happening with the fps controller, not the trigger cube. If i run into the wall, no matter what direction i’m facing, the wall triggers a hit. I want it to work so that if i face away from the wall, there is no collision. Only when the trigger cube, (which again is positioned just in front of my character, parented to the fps controller), touches the wall should there be collision.
Here is the code attached to the trigger cube:
#pragma strict
var playerState : String = "NoWall";
var character : GameObject;
function Start () {
character = GameObject.FindWithTag("Player");
}
function Update () {
var motorScript = transform.GetComponent(CharacterMotor);
if(playerState == "Wall" && CharacterMotor.grounded == false && Input.GetKeyDown("space"))
{
Debug.Log("Wall Run");
playerState = "WallRun";
character.transform.Translate(0, 10, 0);
}
if(playerState == "WallRun" && CharacterMotor.grounded == true)
{
playerState = "NoWall";
Debug.Log("Nowall");
}
Debug.Log(playerState);
}
function OnTriggerEnter(collisionInfo : Collider)
{
if(collisionInfo.gameObject.tag == "wall")
{
Debug.Log("Wall Hit");
playerState = "Wall";
}
}
function OnTriggerExit(collisionInfo : Collider)
{
if(collisionInfo.gameObject.tag == "wall")
{
Debug.Log("Wall Leave");
playerState = "NoWall";
}
}
So again, i have a wall with normal collision. I have a duplicate wall with Is Trigger selected and with a tag of “wall”. I have a cube, parented to the FPS Controller, set to Is Trigger. I have tried doing a Raycast, but I’m not having any luck there whatsoever. If this whole trigger cube thing isn’t even possible the way i’m doing it, then that’s my bad. Thanks in advance for any help! Here is the positioning: