i am trying to let my player collide with the enemy object (what is in this case a cactus) and give the player damage.
i have tried it and it did nothing after a test with the debug.log i notes that my ColliderEnter did not detect the cactus when colliding
i want to have it in an array so that it is a bit more organized with the enemy objects / npc’s
i have the script on top of an empty GameObject called player i did try to put the script on top of my cube but it diddent work can somebody help me thanks in advents
OnCollisionEnter only works, if one of the GameObjects has a non kinematic rigidbody attached to it (See API: Unity - Scripting API: Collider.OnCollisionEnter(Collision) (unity3d.com)). Is that the case?
Also: Put a Debug.Log in your OnCollisionEnter without any conditions, to see if it gets called at all. Right now it might get called, but not meet the condition.
it has not an rigibody collider because if i put a rigibody collider in it my player will react totally freaked out i use an player controller component as for the other option i did tried it and as i suspected it diddent work because he doesent know what to collide with that is my thought at least
Did you already debug it, to see what objects the collision.gameObject and EnemyList[0] are ? If the OnCollisionEnter is fired but doesn´t enter your condition, the objects you compare are not the same. Check if both gameObjects are really the objects you expect
if you look at image h you can see that i put the enemy gameobject what i want to collide with (in this case cactus) inside of the array of enemylist it is the first of the list so that is zero
yes but still, did you set a breakpoint and check why your condition is false (used the inspector to check the objects that are compared) ?
It also could be, that the condition is not true, because the objects point on different references in the (internal) memory. Even in the docu they check properties of the gameobject (like tag or name) and not the whole object: Unity - Scripting API: Collision.gameObject
I would just put a tag to all your enemy gameObjects and check if the tag is equal:
That does not change the basic requirements of OnColliisionEnter(), as specified in the documentation and repeated above by Sphinks. You are NOT going to get OnColliisionEnter() called unless you have a non-kinematic Rigidbody on at least one of the two items colliding. That’s not negotiable, freakouts or not.
What is that? Are you talking about a CharacterController? Those do NOT use the physics system. They live completely outside of physics. Perhaps you are looking for something like this:
that maybe it yeah as for the fisics what used to freak out i have watched a video of how to make a third person character with the use of cinemachine to get a third person camera orbit he used a character controller and put his own line of code to use his own vellocity and gravety if i put a rigibody collider on it it will freak out i tested this i can give what you advised a try tho
yeah that can work only if i put an tag in it i must have an entire line of code with tons of diffrent tags to specifie witch enemy does what type of damage i wanted it all orgenised by using an list or array to simply drag the enemy object or npc into the list and simply specify witch enemy in my list i want to use by simply going by the number in the list
Use isKinematic on your Rigidbody. This will exclude it from physics and you can move it around using the transform or Rigidbodys MovePosition to have FixedUpdate Interpolation for your Colliders. It should not effect anything like that.