void FixedUpdate()
{
// if(!WallColl || onGround())
// {
//if (HoldingStickImp)
//{
// HoldingStickImp = false;
// Input.ResetInputAxes();
//}
float move = Input.GetAxis("Horizontal");
//Physics2D.Raycast(checkWall.origin, checkWall.direction, checkWallDist, wallMasks).collider
if (move > 0 && FacingRight || move < 0 && !FacingRight)
{
if (rayhit.distance == checkWallDist)
{
rb.velocity = new Vector2(0.0f, rb.velocity.y);
}
else if (rayhit.distance != 0)
{
rb.velocity = new Vector2(right * (-1.0f * rayhit.distance), rb.velocity.y);
}
else
{
rb.velocity = new Vector2(move * speed, rb.velocity.y);
}
}
else
{
if (rayhit.distance == checkWallDist)
{
rb.velocity = new Vector2(0.0f, rb.velocity.y);
}
else if (rayhit.distance != 0)
{
rb.velocity = new Vector2(right * (-1.0f * rayhit.distance), rb.velocity.y);
}
else
{
rb.velocity = new Vector2(move * (speed / 2), rb.velocity.y);
}
}
//Animations for moving left and right
if (PlayerAnim)
{
if (move!=0 && onGround())
{
PlayerAnim.SetBool("Move", true);
}
//else if (!onGround() && rb.velocity.y>0 && !PlayerAnim.GetBool("Jump"))
//{
// PlayerAnim.SetBool("Jump", true);
//}
else if (!onGround() && rb.velocity.y <= -2f && !PlayerAnim.GetBool("Fall"))
{
PlayerAnim.SetBool("Fall", true);
}
else
{
PlayerAnim.SetBool("Move", false);
}
}
// Check if the sprite needs to flip
if (move > 0 && !FacingRight) {
if (onGround())
{
Flip();
}
}
else if (move < 0 && FacingRight)
{
if (onGround())
{
Flip();
}
}
// Dictate the player's direction
if (CharacterBehavior.FacingRight) {
Dir = Vector2.right;
} else {
Dir = Vector2.left;
}
// If the player needs to jump now, JUMP!
//if (jumpNow)
//{
// CheckHoldingStickImp();
// ////Force added for up direction
// //rb.velocity = new Vector2(rb.velocity.x,0);
// //rb.AddForce(new Vector2(0, jumpspeed), ForceMode2D.Impulse);
// //jumpNow = false;
// //anim.SetBool ("Ground", false);
//}
}