Disable Collision
by TigerHeros · in Torque 3D Professional · 08/03/2010 (10:28 am) · 3 replies
Hi All
I have disabled enter a car on Collision .I am trying to create a button function which allows the player to enter the car when he is click on it.
How can i identify the person is near the Collision Object or an car .
I have disabled enter a car on Collision .I am trying to create a button function which allows the player to enter the car when he is click on it.
How can i identify the person is near the Collision Object or an car .
About the author
#2
There exists several Resources that show how to enable such a thing... but basically you press a button and send a raycast which includes some logic to do something if the raycast hits a vehicle.
Let's start with a keybind first, in default.binds.cs
You could put this code in scripts/server/commands.cs:
This is a "universal" raycast function. I do this so as not have to duplicate the same code everytime I need to throw a raycast:
I extracted this from the old FPS Genre Kit without testing, but hopefully I got everything needed for this to work.
08/03/2010 (3:18 pm)
At one time the FPS Example had that feature... but looks like it got removed and replaced with the stupid onCollision method.There exists several Resources that show how to enable such a thing... but basically you press a button and send a raycast which includes some logic to do something if the raycast hits a vehicle.
Let's start with a keybind first, in default.binds.cs
function doMountVehicle(%val)
{
if (%val)
commandToServer('MountVehicle');
}
moveMap.bind(keyboard, "m", doMountVehicle);You could put this code in scripts/server/commands.cs:
function serverCmdMountVehicle(%client)
{
%player = %client.player;
if(!isObject(%player) || %player.getState() $= "Dead" || !$Game::Running)
return;
// TODO: Can (will probably) add seat switching right here.
%range = 20;
%mask = $TypeMasks::VehicleObjectType;
%searchResult = %player.doRaycast(%range, %mask);
if (%searchResult && %player.mountVehicle)
{
%vehicle = firstWord(%searchResult);
if (!%vehicle.mountable)
{
messageClient(%client, 'MsgMountFailed', '\c2Vehicle is not useable.');
return;
}
%vel = vectorDot(%vel, vectorNormalize(%vehicle.getVelocity()));
if (%vel <= %vehicle.getDataBlock().maxMountSpeed)
{
messageClient(%client, 'MsgMountSuccess', '\c2Entering %1.', %vehicle.getDataBlock().nameTag);
%player.mountVehicles(false);
%vehicle.getDataBlock().mountPlayer(%vehicle, %player);
return;
}
else
{
messageClient(%client, 'MsgMountFailed', '\c2Cannot enter a moving vehicle.');
return;
}
}
else
{
messageClient(%client, 'MsgMountFailed', '\c2No vehicle in range.');
return;
}
}This is a "universal" raycast function. I do this so as not have to duplicate the same code everytime I need to throw a raycast:
// A raycast helper function to keep from having to duplicate code everytime
// that a raycast is needed.
// %this = the object doing the cast, usually a player
// %range = range to search
// %mask = what to look for
function ShapeBase::doRaycast(%this, %range, %mask)
{
// get the eye vector and eye transform of the player
%eyeVec = %this.getEyeVector();
%eyeTrans = %this.getEyeTransform();
// extract the position of the player's camera from the eye transform (first 3 words)
%eyePos = getWord(%eyeTrans, 0) SPC getWord(%eyeTrans, 1) SPC getWord(%eyeTrans, 2);
// normalize the eye vector
%nEyeVec = VectorNormalize(%eyeVec);
// scale (lengthen) the normalized eye vector according to the search range
%scEyeVec = VectorScale(%nEyeVec, %range);
// add the scaled & normalized eye vector to the position of the camera
%eyeEnd = VectorAdd(%eyePos, %scEyeVec);
// see if anything gets hit
%searchResult = containerRayCast(%eyePos, %eyeEnd, %mask, %this);
return %searchResult;
}I extracted this from the old FPS Genre Kit without testing, but hopefully I got everything needed for this to work.
#3
Thank you Michael Hall... It works fine and Good. Really Great work...
08/04/2010 (8:09 am)
Thank you Marcus for your reply...Thank you Michael Hall... It works fine and Good. Really Great work...
Torque 3D Owner Marcus L
since i posted in the first place, i can share how i think this can be done. I would probably look into the players update code in c++ side. Maybe do some raycasts, or something. If you turn on the "Player Render Collision" in Visibility layers in the world editor, you can see that there is some existing code that checks what collision objects surrounds you. You can probably try to use that code as a starting point.