1
\$\begingroup\$

Okay this is a hard one to explain so I’ll try my best.

Basically every time my enemy class updates, it runs a SightCone Sensor Contact List test, so this is every single frame it checks for all the possible contacts in it’s sensor.

What I’m finding is that if I’m moving my player character around, the contact list updates perfectly, when the player is in the enemy’s sight, it’s true, when it is out of sight its false,

However if I keep my player still, The contact list always ignores it.

Here is a video showing the behaviour. (the true and false flag is in the top left.)

Here is the code I have. Basically in the Enemy’s update method I run the check (the sightcone is a supplemental body within the enemy class that follows the position and rotation of the enemy body every frame.)

List<Body> coneClip = GetBodiesInContactWithBody(SightCone.Body);


private List<Body> GetBodiesInContactWithBody(Body body)
        {
            var bodiesInContact = new List<Body>();
            var c = body.ContactList;
            while (c != null && c.Next != null)
            {
                if (c.Contact.IsTouching)
                {
                    bodiesInContact.Add(c.Other);
                }
                c = c.Next;
            }
            return bodiesInContact;
        }

I am not sure why this is happening. I don’t know why the contact list isn’t seeing the player, even though the body is still, it still exists, has a shape and position, and 100% exists in the physics world.

Truly hope you can help.

\$\endgroup\$
  • \$\begingroup\$ Is the other body asleep? \$\endgroup\$ – Andrew Russell Jan 11 '14 at 2:01
  • \$\begingroup\$ i have no code whatsoever in my solution that would ever put any body created to sleep. unless farseer automatically puts things that are still to sleep without me knowing. \$\endgroup\$ – Qas Piano Jan 12 '14 at 13:57
  • \$\begingroup\$ Update. so i just learnt something new. you are right it was sleeping. didn;t consider it because i though sleeping was a manual thing, not an automatic farseer engine thing. \$\endgroup\$ – Qas Piano Jan 12 '14 at 14:03
2
\$\begingroup\$

This was solved by setting my body's IsSleepingAllowed variable to false. So the body stays active even when totally still.

Thanks for the help Mr Andrew Russell.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.