Answer the question
In order to leave comments, you need to log in
Character management in a 3D Android game?
Hello everyone, I'm making a game (FIRST) and I ran into such a problem that I need to make control.
I searched the entire Internet and found only a tutorial on 2D control, everything works, but for some reason my character model turns 180 degrees. I need to make sure that the character does not turn around and turns to the right and to the left ( I MADE BUTTONS TO CONTROL LEFT AND RIGHT
public Rigidbody rb;
public float playerSpeed;
public float jumpPower;
public int directionInput;
public bool groundCheck;
public bool facingRight = true;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if ((directionInput < 0) && (facingRight))
{
Flip();
}
if ((directionInput > 0) && (!facingRight))
{
Flip();
}
groundCheck = true;
}
void FixedUpdate()
{
rb.velocity = new Vector2(playerSpeed * directionInput, rb.velocity.y);
}
public void Move(int InputAxis)
{
directionInput = InputAxis;
}
public void Jump(bool isJump)
{
isJump = groundCheck;
if (groundCheck)
{
rb.velocity = new Vector2(rb.velocity.x, jumpPower);
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
) .
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question