I have written out the following collision script that works for what happens when the player hits an object. I have duplicated these obstacles and the code seems to be working for the duplicated objects. However, once I change the scaling on one of them, the player goes right through. Not sure what is going on here?
using UnityEngine;
public class PlayerCollision : MonoBehaviour{
public PlayerMovement movement;
void OnCollisionEnter (Collision collisionInfo)
{
if(collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
}
}
}
I made sure that the objects all have the correct tags within the program and everything seems to be the same since they are exact duplicates. Is Trigger is also not selected.
CodePudding user response:
Did you try to Debug.Log and see if it actually does collide and also if it does match the tag? If non of them triggers that means that your colliders on the objects do not collide for some reason. Possibly either because they are too small, gets deactivated, or is non existent. Check on the gameObjects and see how the collider looks after you scale them and make sure it covers the gameObject as intended.