Page 1 of 1

Pickup object (bonus,weapon, etc)

Posted: Mon Oct 19, 2009 6:06 pm
by Serg88
Hi People, sorry for my english,
I make my first game and I wish to make that player can pickup something
for example when player approach to NPC, he can press "action-key" and talk with him or when walk near bonus, he can pickup him.

I wanted make its with collision model, but i don`t know how re-define this event, player only stoped, As though before it a wall.


In advance thanks, yours faithfully Sergey.

Posted: Mon Oct 19, 2009 7:51 pm
by andrei25ni
I'm using a different method.

I created a line in front of the player, pointing at where he looks.
Then, when the "action" key is pressed I check for two things: if the object I want to interact with is in front of the player (intersects the line), and if the distance to that object from the player is a specific amount.

If those two conditions return true, then your player is in front of an object that he can pick up/interact with.

Hope this helps.

Posted: Tue Oct 20, 2009 3:38 pm
by Serg88
i relying that it uses

Code: Select all

virtual ISceneNode * 	ISceneCollisionManager::getSceneNodeFromRayBB (core::line3d< f32 > ray, s32 idBitMask=0, bool bNoDebugObjects=false)=0
function?

in this case does not need to check the length, or use another method?

passing the question: What is idBitMask?

Posted: Tue Oct 20, 2009 9:27 pm
by B@z
you have an array for your npcs right?
then easy

Code: Select all

for (int i = 0; i < npcs.size(); i++)
{
  if (npcs[i]->getPosition().getDistanceFrom(node->getPosition() < 50)
  {
    // the npc is within a circle radius 50
    // check if its before the player
  }
}

Posted: Tue Oct 20, 2009 10:40 pm
by Serg88
great thanks, your`s version realy easy :)))))

PS
but if i standing near the door this code will not work :(

Re:

Posted: Sun Jan 19, 2014 1:51 am
by serokon
andrei25ni wrote:I'm using a different method.

I created a line in front of the player, pointing at where he looks.
Then, when the "action" key is pressed I check for two things: if the object I want to interact with is in front of the player (intersects the line), and if the distance to that object from the player is a specific amount.

If those two conditions return true, then your player is in front of an object that he can pick up/interact with.

Hope this helps.
WooooW Thanks in Advance.
I was just at some of this moments where you are unhappy with your idea on how to implement the next step and then I saw your post.
Btw I will not use a line: smgr.getSceneCollisionManager.getSceneNodeFromScreenCoordinatesBB(getVector2dip(MouseState.Position.X,MouseState.Position.Y));
(I play around with a fps game).
Have a nice day

Re: Pickup object (bonus,weapon, etc)

Posted: Wed Jan 22, 2014 2:39 am
by thanhle
You want to make sure your collision radius is close to the character.

You might want to get the approximate radius:

To get the character Actual boundingbox = originalBoundingbox*scale

radius = SQRT( (0.5*baseBoxWidth)^2 + (0.5*baseBoxLength)^2 ) + someOffset

Regards
thanh

Re: Pickup object (bonus,weapon, etc)

Posted: Wed Jan 22, 2014 8:43 am
by mikkis
Or calculating
long DIST ;
and using square-distances and checking at them (so not using sqrt which is slow).
someOffset must be then squared as well.

Re: Pickup object (bonus,weapon, etc)

Posted: Wed Jan 22, 2014 9:33 am
by thanhle
:).
SomeOffSet is not square. It's an estimated gap.

Or just using

max(lengh, width)