I am trying to make a wall that the player can NOT get past. The player moves with 32 pixels per button-press, as soon as there’s collision it shouldn’t be able to move any further.
Below is the current code, any ideas?
void OnTriggerEnter(Collider otherObject)
{
if (otherObject.tag == "walls-blocks")
{
Debug.Log("(PlayerHitWall) Player hit: " + otherObject.name);
if (w == true)
{
gameObject.transform.position = lastPosition;
}
}
}
By the way “w == true” refers to keyboard input booleans:
if (Input.GetKeyDown("w"))
{
w = true;
s = false;
a = false;
d = false;
}
and lastPosition refers to:
lastPosition = gameObject.transform.position; (in the Update function)