I have this script so when i walk into the object with the tag stuck speed = 0.
I do this to prevent some bugs.
So when i walk into the object now, speed = 0. But then i can’t move left or right and im just stuck in the collider. I want it so i don’t get stuck and i freely can walk around when i collide with it, without getting stuck.
Here is the script that i made:
#pragma strict
var mSpeed : float = 3;
var walk = false;
function Start () {
}
function Update () {
if(Input.GetButton("right"))
{
transform.position = transform.position + Vector3(mSpeed,0,0) * Time.deltaTime;
}
if(Input.GetButton("left"))
{
transform.position = transform.position + Vector3(-mSpeed,0,0) * Time.deltaTime;
}
}
function OnCollisionEnter2D(coll: Collision2D)
{
if(coll.gameObject.tag == "stuck")
{
mSpeed = 0;
}
}