Hello. I want my Player to change direction when he hits a wall by 180 degrees, but im not sure how to do it. I also want him to change the facing direction 180 degrees at the same time. The movement is just fine, its just the changing of direction i need some help with Code (CSharp): public class MoveTest : MonoBehaviour { public float Speed = 0.3f; private void FixedUpdate() { transform.Translate(Speed * Time.deltaTime, 0, 0); } void OnTriggerEnter(Collider col) { if (col.gameObject.CompareTag("xFlip")) { //Make the direction of travel rotate 180 Degrees. //Make the facing direction rotate 180 Deg. Debug.Log("Hit"); } } }
I have tried doing that exact solution multiple times before, and I never got that to work. Now I got it to work, looks like I had some trouble with the trigger.
Made some minor changes and now it works just as I want it to Code (CSharp): using UnityEngine; public class MoveTest : MonoBehaviour { public float Speed = 0.3f; private void FixedUpdate() { //moves the Player at a constant speed. transform.Translate(-Speed * Time.deltaTime, 0, 0); } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "xFlip") { // Makes the facing and movement change by 180. transform.Rotate(0, 180, 0); } } }