- Home /
infinite runner killing game object
hi all, I am new to unity and I am building an infinite runner with a car.i have written some code for the car's movement. The car will be destroyed when it hits the ground in an inverted position and I couldn't figure this out.Any help would be extremely useful.,
Answer by TanselAltinel · May 05, 2018 at 07:12 PM
Hi,
There might be a lot of different approach to this. One solution I'd suggest to have a trigger area (preferably a small sphere) at top of the car, and whenever car collides with the ground in an inverted position, that sphere would trigger with ground and give you your event.
I presume you already know about colliders, triggers, OnTriggerEnter type of built-in functions.
I tried using ontriggerenter() method but it won't work.I used a gameobject and assigned it to car and when it got inverted it was in the same way
OnTriggerEnter wont work in later UnityPatches for some reason UNLESS you add a rigidbody to the same object. If you dont want a rigidbody you can disable gravity on the component
What exactly did you do? Did you have any debug line working?
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Also, you'll have to tick isTrigger checkbox on your object.