In essence I am creating a platform game, on the screen are three floors, my character (on the ground floor) should hit an obstacle and bounce back a short distance. However the character is bouncing back a long way and I cannot work out how to resolve it.
This is the script I have created
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
GameObject[] charaters = GameObject.FindGameObjectsWithTag("Player");
foreach(GameObject charater in charaters){
//get the CharaterControllerScript
CharaterControllerScript controlScript = (CharaterControllerScript)charater.GetComponent(typeof(CharaterControllerScript));
//stop all charater movement
controlScript.Move = 0;
}
GameObject charaterCollision = other.gameObject;
charaterCollision.rigidbody2D.position = new Vector2(1, charaterCollision.rigidbody2D.position.y);
}
}
I believe the problem with this is the last line of the “if” statement. I have tried several different options but the character keeps bouncing back to the beginning of the scene.
I need it to only bounce back a few pixels.
NB: I have tried adding a 2d material to the obstacle, but that bounce the character up to the next floor.