- Home /
Problem is not reproducible or outdated
Detect collision point??
Hello again!
I'm trying to make a different function, depending on where the car collides (front, left, right, rear), like activate an object simulating damage to the vehicle.
With some colliders (cubes) inside it it is not possible to detect its collision, but how do I do it? Thank you! (here I leave a photo of the example).
Answer by nickostan · Jun 06, 2020 at 12:55 AM
I think this is what you want:
https://docs.unity3d.com/ScriptReference/ContactPoint-point.html
Collisions store information about the point of collision
Yes, it is what I was looking for, but how can I deter$$anonymous$$e specifically what point each one is? (the front, or the left, etc. ..).
Because it shows me coordinates on the console.
Thank you!
using UnityEngine;
using System.Collections;
public class Damage_Script : $$anonymous$$onoBehaviour {
void Start (){
}
void Update (){
}
void OnCollisionEnter(Collision other)
{
print("Points colliding: " + other.contacts.Length);
print("First point that collided: " + other.contacts[0].point);
}
}
One way you could handle this is by making several child gameobjects, each with their own colliders i.e. one for the left front bumper, one for the right front bumper, etc. Then have different logic handing each of those triggers.
I'm not sure what you're trying to do, but you could subtract the collision point from your car transform and get a relative vector pointing in the direction of collision. The x component of the vector would be negative for a right side collision, and positive for a left side collision.