Statyk
Schrödinger's Mod
Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation:
241
|
RE: Killed because too far from a grabbable object
(12-23-2011, 01:44 AM)Apjjm Wrote: A similar problem was faced when i was detecting the lantern for my "Observable" map & engine.
Quick overview of one potential solution:
Create a copy of block_box.ent - call it something like "detector.ent". Open it in the model editor and delete it's body. Create a new sphere shape and scale it to be the radius around the object the player must be within to survive. Make the sphere a body, attach the body the sub-mesh. Disable "collides character" and "collides non-character" in the body properties, give the body 0 mass.
In the script for your level, use AddAttachedPropToProp to attach this detector entity to your grabbable object. Then use AddEntityCollideCallback w/ the name of the attached prop and use this to determine if the player leaves the radius of the object. E.g:
void OnStart()
{
AddAttachedPropToProp("PlayerDetector","Grabbable_Object","detector.ent",0,0,0,0,0,0);
AddEntityCollideCallback("Player","PlayerDetector","cbGrabbableRadiusCollide",false,0);
}
void cbGrabbableRadiusCollide(string &in asParent, string &in asChild, int alState)
{
if(alState == 1)
{
//Player has entered the radius
}
else
{
// Player has left the radius
}
}
You will want to couple this with SetEntityPlayerInteractCallback to determine if the player has picked up your grabbable object yet.
Edit: clarity. So much was said here but wow... Genius. I need to think a little further into this, I could use this trick for my campaign a bit =]
|
|
12-24-2011, 12:19 AM |
|