Pickup object (bonus,weapon, etc)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

Pickup object (bonus,weapon, etc)

Post 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.
from Russia with love :))))
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post 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.
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

Post 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?
from Russia with love :))))
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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
  }
}
Image
Image
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

Post by Serg88 »

great thanks, your`s version realy easy :)))))

PS
but if i standing near the door this code will not work :(
from Russia with love :))))
serokon
Posts: 11
Joined: Wed Mar 27, 2013 1:43 am

Re:

Post 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
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Pickup object (bonus,weapon, etc)

Post 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
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Pickup object (bonus,weapon, etc)

Post 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.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Pickup object (bonus,weapon, etc)

Post by thanhle »

:).
SomeOffSet is not square. It's an estimated gap.

Or just using

max(lengh, width)
Post Reply