- Home /
Detect if object with Hinge Joint is moving
I've been making sound system for door, which is with hinge joint. Open door sound works, but i can't make door play looping sound when it is rotating. I've tried rigidbody.IsSleeping, but the problem is, that if I drag door a bit and release it (to rotate by itself), script detects that rigidbody is sleeping. I also tried rigidbody.velocity - same results.
So how I can detect if door has ANY rotation in progress?
attach a $$anonymous$$AR$$anonymous$$ER OBJECT to the outside edge of the door.
that is, an empty object - a "marker object" this is incredibly common in video games. when I say "attach" I just mean drag it inside the "folder" - so it's a child.
now simply look at the velocity of that object. Cheers
Answer by sparkzbarca · Nov 20, 2012 at 04:32 PM
motion is change over time.
void update(){ lastPos; CurrentPos;
if (CurrentPos == null)
{
lastPos = transform.position;
CurrentPos = transform.position;
}
else{
lastPos = CurrentPos;
CurrentPos = transform.position;
}
if (vector3.distance(LastPos,CurrentPos) > mathf.epsilon)
{
object moved;
}
}