OnTriggerEnter doesn't work with the Character Controller
Asked Answered
G

3

0

I’ve made a player with a Character Controller, and no other Collider.

I am trying to use the function OnTriggerEnter or OnTriggerStay, but it doesn’t seem to work with the Character Controller.

Does anyone have any idea as to why? Or maybe what else I could do?

Guadiana answered 12/3 at 20:1 Comment(1)

Yeah that's absolutely possible with the runtime APIs and it does it blazingly fast too. Read the API docs here https://brainfail.000webhostapp.com/pivotmodder_runtime_api_docs/html/class_pivot_modder_runtime_1_1_pivot_modder_runtime.html

Icebound
L
0

Make sure that the Collider that is attached to the script object is tagged as Is Trigger

And if it doesn’t work try something like this:

Note: this code is not C#, it’s legacy JS-like language

function OnTriggerStay (Col : Collider)
{
	if(Col.tag == "Player")
	{
		//Do magic
	}
}

Attach it to the gameobject that has the Collider set to Is Trigger And be sure to tag the player as "Player"

If it doesn’t work post some pictures and explain more what is happening

Logwood answered 12/3 at 20:3 Comment(0)
G
0

There is this method for collisions on Character Controller:

I notice in the docs, under Inherited Members that isTrigger is actually listed. Perhaps this will actually work to change the CC collider to a trigger? May cause problems, who knows, you can but only try.

Glop answered 12/3 at 20:5 Comment(1)

The thing is, I am using a character controller - not a rigidbody

Guadiana
L
0

Make sure that the Collider that is attached to the script object is tagged as Is Trigger

And if it doesn’t work try something like this:

Note: this code is not C#, it’s legacy JS-like language

function OnTriggerStay (Col : Collider)
{
	if(Col.tag == "Player")
	{
		//Do magic
	}
}

Attach it to the gameobject that has the Collider set to Is Trigger And be sure to tag the player as "Player"

If it doesn’t work post some pictures and explain more what is happening

Logwood answered 12/3 at 20:3 Comment(0)
M
0

A CharacterController implicitly comes with a collider, but behaves a bit different when it comes to collision callbacks. After some testing in Unity 2021.3.33f I can confirm the following:

  • OnTriggerEnter works
  • OnCollisionEnter does NOT work
  • Instead of that, you should use OnControllerColliderHit when moving the CharacterController with Move

So if OnTriggerEnter is not working for you, double check whether the collider you are colliding against is actually marked as trigger, via the Is Trigger checkbox on it, or whether your Character Controller has non-zero height/radius. If all that is in order, it should work, otherwise it is most likely a bug in the version you are using.

Maracanda answered 12/3 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.