PDA

View Full Version : Collision with newly created entites



Pleng
05-17-2009, 08:01 AM
When my player picks up an item it is removed from the map. When he drops it, the item is recreated on the map.

I have a hidden entity on my map(moneybag_zone), which is designed to detect when an item is dropped on top of it. I have the following code inserted in the OnCollision() function:



//put the NAME of the entity for of correct item
//here:
local item="moneybag"

local myent=entity; //the entity we have collided with

local correctitem=-1 //Don't worry about this.
//Because the item may not exist on the map
//(ie we may be carrying it), we have to set
//this variable to -1.



//If the object does exist then we need to
//get it's ID

if not (GetEntityByName(item)==nil) then

correctitem=GetEntityByName(item):GetID();

end

LogMsg(correctitem);
LogMsg(myent);


Log messages are generated every time the player collides with the zone, and when, for example, a barrel is pushed over the zone. However the collision is NOT detected when an entity (for instance a money bag or a mushroom) is created on top of the zone.

Is there any way around this?

fdaniels
05-17-2009, 11:03 AM
Have you tried creating the item, then when it appears on the map have its script move it a pixel or so? Should this not activate the collision detection?

Pleng
05-17-2009, 11:07 AM
Hi, yes I thought of that after posting, but it still doesn't seem to trigger the collision function.

Seth
05-17-2009, 12:07 PM
Hmm, I'm not sure I understand the problem.. is it you can't get a "just spawned" entity to generate a collision call against another non-moving entity?

Should be possible, I do something similar for the player's "damage swipe" thingie in tree world. (It spawns without moving, and can hit blocks, which aren't moving)

Does your money bag detector do a this:SetCollisionListenCategory() for the correct type of thing that the item is? (Whatever category the item has set itself to.. default is "Entity" but one or more is possible at the same time)

Pleng
05-17-2009, 03:22 PM
Hi Seth

Yes it's newly spawned items not colliding registering collisions.

The moneybag's detector has the following code in post init()



this:SetCollisionListenCategory(C_CATEGORY_ENTITY, true);
this:SetCollisionListenCategory(C_CATEGORY_PLAYER, false);


and the money bag itself has this:



this:SetLayerByName("Detail 2");
this:SetDensity(1);
this:SetGravityOverride(0); //so we don't move
this:SetCollisionListenCategory(C_CATEGORY_PLAYER, true);
this:SetCollisionListenCategory(C_CATEGORY_ENTITY, true);

//Update every frame!
this:SetRunUpdateEveryFrame(true);


You can check out the issue for yourself with the game that I sent you. Talk to the crew_leader near the crow's nest and offer to sell him a leather jacket. Talk to him again and the crew will push a barrel down. Look in the logs and it will show that collisions have occured. However if you pick up the mushroom or money bag and lay it down on the zone, no collisions occur in the log.

Once again, I'm stumped! :S

Seth
05-17-2009, 08:15 PM
See here (http://www.rtsoft.com/forums/showthread.php?t=2638) and see if that was the problem..!