This project has moved and is read-only. For the latest updates, please go here.

Which Object Collides with another Object

Topics: Developer Forum, User Forum
Jan 3, 2015 at 8:22 PM
I've got a Player, a Weapon and a Bullet Class.
I want to know which player shoots which player. ( later with which weapon)

I find some Code like:

bullet.Body.OnCollision += OnBulletCollision;
    private bool OnBulletCollision(Fixture fix1, Fixture fix2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        if (!toRemove.Contains(fix1.Body))
            toremove = true;
         // Category 10 is the Player Category
        if (fix2.CollisionCategories == Category.Cat10 )
        return true;
with it :
i can Remove every Bullet which was shot.
i know if a player where hit by a bullet.
but how can i return which player hits which player.
so the second player could be "killed"

Example of Displaying this ( in Teeworlds) :
Feb 20, 2015 at 12:41 PM

A body can have an object in it's Userdata field. Create an object like 'bullet' and when fired give it a property stating the shooters name. When it hits get body.UserData and you have the bullet object back.


Mar 9, 2015 at 12:19 PM

instead of giving directly the shooter's name in the UserData field of your bullet object, you should have a Bullet class, containing the FPE body.
You can then give your parent Bullet class as UserData.

When you hit, you can retrieve the parent bullet :
(fix2.Body.UserData as Bullet).PlayerName //Considering PlayerName a string containing the bullet owner