|
|
It is currently Tue May 21, 2024 9:06 am
|
View unanswered posts | View active topics
|
|
|
|
|
Users browsing this forum: No registered users and 1 guest |
|
|
|
|
|
|
|
|
|
Author |
Message |
TE-Noxwizard
Joined: Tue Jun 07, 2005 5:59 pm Posts: 942 Location: Texas
|
Posted: Tue Sep 05, 2006 7:08 pm Post subject: Using a camera to check deploy area
|
|
|
This function checks the deploy area when you use it in a deployable item. It spawns a camera at your desired deployment height, then rotates 360 degrees and checks for objects in the way. If you have an object that decends, you can use the %vert to define how high you want to look striaght up above the deployment area.
Code: | // Function to check deploy area/landing path // Spawn a camera, rotate all the way around and check for objects // -Noxwizard // %pos - deploy position // %height - height to deploy camera // %radius - how far to look around // %vert - how high to look up (dropships)
function checkarea(%client,%pos,%height,%radius,%vert) { %camera = newObject("Camera","Turret",cameraturret,true); GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height));
// Look up if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0")) { %name = GameBase::getDataName($los::object);
if(!%name) %name = getObjectType($los::object); if(%name == "SimTerrain") Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible else Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up."); DeleteObject(%camera); return false; } // Look around for(%i = 0; %i < 6.3; %i = %i + 0.1) { if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i)) { %name = GameBase::getDataName($los::object);
if(!%name) %name = getObjectType($los::object); if(%name == "SimTerrain") Client::sendMessage(%client,0,"You are too close to hills."); else Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up."); DeleteObject(%camera); return false; } } // Now that the circle has completed, deploy DeleteObject(%camera); return true; } |
Code Explaination:
This creates a camera at the player's position at the height defined:
Code: | %camera = newObject("Camera","Turret",cameraturret,true); GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height)); |
This has the camera look straight up for your defined height:
Code: | GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0") |
Put that into an if statement and we can check if there's an object in the camera's line-of-sight. If there's something in the way, we'll get it's name and tell the client that it's in the way, and how high up it is. Unless it's terrain.
Code: | if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0")) { %name = GameBase::getDataName($los::object);
if(!%name) %name = getObjectType($los::object); if(%name == "SimTerrain") Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible else Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up."); DeleteObject(%camera); return false; } |
Now this part's a bit different. We want it to look all the way around, so we will have it look in a lot of directions, by adding 0.1, looking, adding another 0.1, looking, and so on. To do that we use a for loop. We went it to look all the way around, which will be from 0 to 6.28. It's 6.28, because that's just the way circles are handled, instead of degrees it's radians, 6.28 is the same as 360 degrees.
Code: | // Look around for(%i = 0; %i < 6.3; %i = %i + 0.1) { if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i)) { %name = GameBase::getDataName($los::object);
if(!%name) %name = getObjectType($los::object); if(%name == "SimTerrain") Client::sendMessage(%client,0,"You are too close to hills."); else Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up."); DeleteObject(%camera); return false; } } |
So, if there's something in the way, it reports a false value, which will immediately stop checking. If it makes it through all those checks without seeing an object, it will report a true.
To use this, put this in your deployment code:
Code: | // check for other airbases/buildings/etc -Noxwizard %pos = $los::position; if(!checkarea(%client,%pos,95,20,20)) return false; |
What that does is checks the area you've defined. So this spawns a camera up 95 meters above you, then looks up 20 meters, then looks around in a 20 meter radius. If it doesn't find anything, it'll go onto the next items in the deploy code. If it does find something, it will halt the deployment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|
|
|
|
|
| |