- Home /
Question by
$$anonymous$$ · Jul 08, 2019 at 11:18 PM ·
colliderupdateclosest
Can't update collider closestpoint
Hello,
I'm trying to get a collider's closest point to a gameobject with a capsule collider When the capsule intersects the collider, I get a point, but that point doesn't move when the collider move. How do I update the collider.Closestpoint?
Relevant code here:
public class Collision : MonoBehaviour
{
List<Vector3> posContacts = new List<Vector3>();
List<Collider> cContacts = new List<Collider>();
void OnTriggerEnter(Collider other)
{
cContacts.Add(other);
if(posContacts.Count != 0)
{
posContacts.Add(cContacts[cContacts.Count - 1].ClosestPoint(transform.position));
}
else
{
posContacts.Add(cContacts[0].ClosestPoint(transform.position));
}
}
void FixedUpdate()
{
for(int i = 0; i < posContacts.Count - 1; i++)
{
posContacts[i] = cContacts[i].ClosestPoint(transform.position);
}
}
}
The update part doesn't work. Can you help me? Thanks.
Comment
Best Answer
Answer by $$anonymous$$ · Jul 09, 2019 at 08:15 PM
I fixed it, I added some code:
void FixedUpdate()
{
for(int i = 0; i < cContacts.Count; i++)
{
OnTriggerStay(cContacts[i], i);
}
}
void OnTriggerStay(Collider other, int i)
{
posContacts[i] = cContacts[i].ClosestPoint(transform.position);
}
Now I'll need to figure out how to delete contacts going out of the capsule...
Your answer
Follow this Question
Related Questions
Finding Closest Enemy... 2 Answers
Find nearest contact point inside trigger 2 Answers
Why can't compiler find Physics.ClosestPoint or Collider.ClosestPoint? 1 Answer
Find closest point of a sprite to GameObject 2D 1 Answer
Internal collisions 1 Answer