I am trying to make my character flip when it reaches a certain point, but it just disappears if I make him go to the right.,My chararacter just goes down when I try to make it go to the right.
Here's the code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CharacterMovement : MonoBehaviour { public float maxSpeed = 6.0f; public float moveDirection; public bool facingRight = true; private Rigidbody rigidbody; // Start is called before the first frame update void Start() { rigidbody = GetComponent (); }
// Update is called once per frame
void Update()
{
float move = Input.GetAxis("Horizontal");
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void FixedUpdate(){
rigidbody.velocity = new Vector2 (moveDirection * maxSpeed, rigidbody.velocity.y);
if (moveDirection > 0.0f && !facingRight){
Flip ();
} else if (moveDirection < 0.0f && facingRight) {
Flip ();
}
}
void Flip (){
facingRight = !facingRight;
transform.Rotate(Vector3.up, 180.0f, Space.World);
}
}
I am new in this so I thought that you could help me. Any help is appreciated ,I am trying to make my character go to the right and rotate (flip) but instead, he just dissapears. I am new in this so I thought you could help me. Here's the code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CharacterMovement : MonoBehaviour { public float maxSpeed = 6.0f; public float moveDirection; public bool facingRight = true; private Rigidbody rigidbody; // Start is called before the first frame update void Start() { rigidbody = GetComponent (); }
// Update is called once per frame
void Update()
{
float move = Input.GetAxis("Horizontal");
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void FixedUpdate(){
rigidbody.velocity = new Vector2 (moveDirection * maxSpeed, rigidbody.velocity.y);
if (moveDirection > 0.0f && !facingRight){
Flip ();
} else if (moveDirection < 0.0f && facingRight) {
Flip ();
}
}
void Flip (){
facingRight = !facingRight;
transform.Rotate(Vector3.up, 180.0f, Space.World);
}
}
tell me if something's wrong
Your answer
Follow this Question
Related Questions
Character jumps immediately after it's grounded when jump is pressed mid-air 2 Answers
Why is my character flying off screen? 0 Answers
Gravity issue on MouvementController using RigidBody when going down a slope 0 Answers
How can I make the charecter jump in my game with this script I have? 0 Answers
How do you smoothly move/stop the character controller? 0 Answers