triger event
triger event
just like quake,put an rotating weapon in the map, pick it up when the player close to ,how to triger ?
You'd have to do that yourself (perhaps with a custom scene node) or maybe, if you're lucky, you might find some relevant code by scouring this forum with the search function (no guarantees though).
If you're looking for ideas, I'd recommend checking the distance from the gun (which has a rotating animator) to the player, and when the distance is low enough, remove the node and add the gun to the player's inventory.
If you're looking for ideas, I'd recommend checking the distance from the gun (which has a rotating animator) to the player, and when the distance is low enough, remove the node and add the gun to the player's inventory.
-
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
Some physics engines have a "Trigger Mesh" that will do the detection of two objects intersecting for you. PhysX has a trigger object with a callback. Havok has phantom objects that do the same thing.
Otherwise, you could use an AABBox to detect whether the bounding boxes of the player and the weapon are intersecting, then if they are, remove the weapon and add it to the player's inventory.
Otherwise, you could use an AABBox to detect whether the bounding boxes of the player and the weapon are intersecting, then if they are, remove the weapon and add it to the player's inventory.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
The distance check would no doubt be the cheapest one to do, simpler than checking intersection with a box i should think, to be even more cheap you could use the squared distance to avoid the horrible square root operation and just check it against a squared distance threshold for how close the player needs to be to the object.
So basically, every frame:
So basically, every frame:
Code: Select all
for each object of interest:
if player distance from object less than threshold
give the item to the player/whatever is required
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Since the distanceSq check would treat both objects as points, presumably you'd be OK with using aabbox3d::isPointInside() as an alternative.
Code: Select all
bool isPointTotalInside(const vector3d<T>& p) const
{
return (p.X > MinEdge.X && p.X < MaxEdge.X &&
p.Y > MinEdge.Y && p.Y < MaxEdge.Y &&
p.Z > MinEdge.Z && p.Z < MaxEdge.Z);
}
Contrast with vector3df::getDistanceFromSq()
Code: Select all
T getDistanceFromSQ(const vector3d<T>& other) const
{
return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z).getLengthSQ();
}
T getLengthSQ() const { return X*X + Y*Y + Z*Z; }
I know which one I'd rather use if I was concerned about performance.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
It's true, chicks flip for maths nerds. That, plus the obscenely high pay, is why guys are flocking to science subjects in record numbers.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way