The transform keeps moving the player to a spot around the origin instead of relative to the player. This seems like a simple fix, but for the life of me I can’t find it.
#pragma strict
var moveLeft : KeyCode;
var moveRight : KeyCode;
var moveJump : KeyCode;
var moveDown : KeyCode;
var dashToggle : KeyCode;
var dashMax : float = 2;
var dashCharges : float = 2;
var dashDistance : float = 20;
var JumpHeight : float = 20;
var speed : float = 10;
private var isFalling = false;
function Update ()
{
if (Input.GetKeyDown(moveJump) && isFalling == false && !(Input.GetKey(dashToggle)))
{
rigidbody2D.velocity.y = JumpHeight;
isFalling = true;
}
if (Input.GetKey(moveRight))
{
rigidbody2D.velocity.x = speed;
}
else if (Input.GetKey(moveLeft))
{
rigidbody2D.velocity.x = speed *-1;
}
else
{
rigidbody2D.velocity.x = 0;
}
if(Input.GetKey(dashToggle) && Input.GetKeyDown(moveJump) && dashCharges >=1)
{
rigidbody2D.transform.localPosition = Vector2(0,dashDistance);
dashCharges -= 1;
}
if(Input.GetKey(dashToggle) && Input.GetKeyDown(moveLeft) && dashCharges >=1)
{
rigidbody2D.transform.localPosition = Vector2(dashDistance,0);
dashCharges -= 1;
}
if(Input.GetKey(dashToggle) && Input.GetKeyDown(moveRight) && dashCharges >=1)
{
rigidbody2D.transform.localPosition = Vector2(dashDistance,0);
dashCharges -= 1;
}
if(Input.GetKey(dashToggle) && Input.GetKeyDown(moveDown) && dashCharges >=1)
{
rigidbody2D.transform.localPosition = Vector2(0,-dashDistance);
dashCharges -= 1;
}
}