- Home /
Help with some collision mechanics and movement for my game.
So I am trying to make a 3d game in Unity thats sort of like Brawl Stars, and I think I have got some of the mechanics and stuff right, but something is wrong with the collisions. I am using box colliders for my basic player, and I also put them on some obstacles so that the player couldn't pass through them. However, when the player hits a wall or obstacle, I just want it to stop, but instead the player just spins away slowly. I have tried to fix this, but nothing seems to work. I have attached my movement script, and would be more than happy to share screenshots or screen recordings of my issue if need be. Thanks! using System.Collections; using System.Collections.Generic; using UnityEngine; public class playerMovement : MonoBehaviour { [SerializeField] Joystick joystick; [SerializeField] Transform PlayerSprite; public float speed; //public Rigidbody rig; void Start() { //rig = GetComponent<Rigidbody>(); } void FixedUpdate() { if(joystick.Horizontal > 0 || joystick.Horizontal < 0 || joystick.Vertical > 0 || joystick.Vertical < 0) { transform.Translate(Vector3.forward * Time.deltaTime * speed); // rig.MovePosition(transform.forward * Time.deltaTime * speed); PlayerSprite.position = new Vector3(-joystick.Vertical + transform.position.x, 1f, joystick.Horizontal + transform.position.z); transform.LookAt(new Vector3(PlayerSprite.position.x, 0, PlayerSprite.position.z)); transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); } } }