- Home /
Determine object hitting a static collider at update()
So I have a Sphere Collider
for my player and I want to make my player always saving variables (for checkpoints) when my player stays or rolling in a static object.
so my question is, how to determine that this object are hitting an object with Static Collider
within an Update()
function?
Do you need the collider or do you just want to know if it's in range?
i just want to know if it's collider hit my player, i don't need any collider info (but i want to know it's collider are static or not)
a collider is static if it does not have a rigidbody (or rigidbody2d in 2d case)
I'm not entirely sure how to do that in the UpdateFunction, you could do a linecast to all the checkpoints in the scene and check if the distance of the linecast is within a bound such that you would perform your UpdateVariables() with that checkpoint
I'm not sure why you have to perform the check in the Update()
Sorry for not directly answering the question you're asking but is there any specific reason you are not able to do something like below because even if you check somehow in your Update() you need to know if the thing you've collided with is actually a checkpoint so you'll need to check the tag, all which is handled with the OnTriggerEnte/OnCollisionEnterr
OnTriggerEnter(Collider other)
{
if (other.tag == "Checkpoint")
UpdateVariables();
}
Sorry I couldnt be more help
Answer by BMayne · Dec 31, 2014 at 01:51 AM
Hey there,
You can do this by using Physics.SphereCast. I would suggest using layers too.
http://docs.unity3d.com/ScriptReference/Physics.SphereCast.html
Regards,
i sorry to ask you again, but how i fill the layer$$anonymous$$ask
parameter? in the documentation there is something like Bit Shift
that i didn't understood it well
Without knowing how bit shifting works you can just do this Layer$$anonymous$$ask.NameToLayer("The name of the layer you want to check");
thanks... seems there is no better answer (for now).
i will mark this as solved if there is no better answer.