- Home /
Collission and Trigger on Same object
So I'm working on creating like a health-orb pickup item. I need the orb itself to have physics detection so it bounces on the ground, but I also need a trigger to tell if the player is near enough to pick it up (but not directly on top of it, I want the orbs to sort of 'float' to the player if they're near enough).
So I've been doing some research and I'm a bit confused on the topic. From what I gather you can only have one collider of each type on a single game object (one box, one sphere, etc.) and multiple colliders will be treated as a compound collider. So you can only have a single game object as either physics or trigger.
So I created a parent game object that had a sphere collider to detect physics (works fine!) Then I created a child object with a sphere collider at a much larger scale with a trigger and script attached.
However, the child sphere seems to be having a physics reaction with the player where it 'pushes' them back a bit, even though it's sphere is set to trigger only.
So then I tried unparenting the child and the same thing still happens where the is-trigger sphere is causing my player to 'push' back.
I'm confused on what's causing this!
Edit:
I kept playing with this and decided since I couldn't get the previous way to work that I would create it as a single gameObject. So I have a sphere with a rigidbody and collider which behaves as normal and then a script to check for distance (instead of a trigger).
However, when I get to the point where I move the item it still has the same issue where it sorta pushes the player.
I even set them on Physics layers where they ignore eachother.
I'm at a loss with why this is happening!
the health-orb Update: (placed on a gameobject with a rigidbody and sphere collider)
void Update(){
//Rotate this item to face the player at all times
transform.LookAt(transform.position + Camera.main.transform.rotation * Vector3.back,
Camera.main.transform.rotation * Vector3.up);
//Keep track of how far the item is from Snow
distanceSnow = Vector3.Distance(transform.position, snow.transform.position);
RaycastHit hitInfo;
//If the player hasn't reached the orb, reduce it's lifespan
if(!absorbing){
if(Physics.Raycast (transform.position, -Vector3.up, out hitInfo)){
if(hitInfo.distance <= 0.04)
checkingDistance = true;
//delay a moment before checking for distance
}
if(checkingDistance){
if(distanceSnow <= pickupRange){
absorbing = true;
}
lifespan -= Time.deltaTime;
if (lifespan <= 0)
Death();
}
} else {
//If the player has neared the orb start floating towards the player
this.rigidbody.isKinematic = true;
speed += speedIncrease;
speed = Mathf.Clamp (speed, 0, 6);
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position,
new Vector3(snow.transform.position.x,
snow.transform.position.y + 0.25f,
snow.transform.position.z), step);
if(distanceSnow <= 0.26f)
GrantCP();
}
}
Let me know if you managed to find a solution to your problem.