mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-22 12:55:34 +00:00
Adds some example components, game objects and the tools and scripts to utilize them.
This commit is contained in:
parent
7bf49f0670
commit
6fe0b1789d
32 changed files with 1812 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<GameObjects>
|
||||
<GameObject>
|
||||
<Name>ScriptedTriggerObject</Name>
|
||||
<TAMLPath>data/EC/scripts/gameObjects/ScriptedTriggerObject.taml</TAMLPath>
|
||||
<ScriptPath>data/EC/scripts/gameObjects/ScriptedTriggerObject.cs</ScriptPath>
|
||||
</GameObject>
|
||||
<GameObject>
|
||||
<Name>PlayerObject</Name>
|
||||
<TAMLPath>data/EC/scripts/gameObjects/playerObject.taml</TAMLPath>
|
||||
<ScriptPath>data/EC/scripts/gameObjects/playerObject.cs</ScriptPath>
|
||||
</GameObject>
|
||||
<GameObject>
|
||||
<Name>spectatorObject</Name>
|
||||
<TAMLPath>data/EC/scripts/gameObjects/spectatorObject.taml</TAMLPath>
|
||||
<ScriptPath>data/EC/scripts/gameObjects/spectatorObject.cs</ScriptPath>
|
||||
</GameObject>
|
||||
<GameObject>
|
||||
<Name>ThirdPersonPlayerObject</Name>
|
||||
<TAMLPath>data/EC/scripts/gameObjects/ThirdPersonPlayerObject.taml</TAMLPath>
|
||||
<ScriptPath>data/EC/scripts/gameObjects/ThirdPersonPlayerObject.cs</ScriptPath>
|
||||
</GameObject>
|
||||
<GameObject>
|
||||
<Name>FirstPersonArms</Name>
|
||||
<TAMLPath>data/EC/scripts/gameObjects/FirstPersonArms.taml</TAMLPath>
|
||||
<ScriptPath>data/EC/scripts/gameObjects/FirstPersonArms.cs</ScriptPath>
|
||||
</GameObject>
|
||||
</GameObjects>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
function execGameObjects()
|
||||
{
|
||||
//find all GameObjectAssets
|
||||
%assetQuery = new AssetQuery();
|
||||
if(!AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset"))
|
||||
return; //if we didn't find ANY, just exit
|
||||
|
||||
%count = %assetQuery.getCount();
|
||||
|
||||
for(%i=0; %i < %count; %i++)
|
||||
{
|
||||
%assetId = %assetQuery.getAsset(%i);
|
||||
|
||||
%gameObjectAsset = AssetDatabase.acquireAsset(%assetId);
|
||||
|
||||
if(isFile(%gameObjectAsset.scriptFilePath))
|
||||
exec(%gameObjectAsset.scriptFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
function spawnGameObject(%name, %addToMissionGroup)
|
||||
{
|
||||
if(%addToMissionGroup $= "")
|
||||
%addToMissionGroup = true;
|
||||
|
||||
//find all GameObjectAssets
|
||||
%assetQuery = new AssetQuery();
|
||||
if(!AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset"))
|
||||
return; //if we didn't find ANY, just exit
|
||||
|
||||
%count = %assetQuery.getCount();
|
||||
|
||||
for(%i=0; %i < %count; %i++)
|
||||
{
|
||||
%assetId = %assetQuery.getAsset(%i);
|
||||
|
||||
%gameObjectAsset = AssetDatabase.acquireAsset(%assetId);
|
||||
|
||||
if(%gameObjectAsset.gameObjectName $= %name)
|
||||
{
|
||||
if(isFile(%gameObjectAsset.TAMLFilePath))
|
||||
{
|
||||
%newSGOObject = TamlRead(%gameObjectAsset.TAMLFilePath);
|
||||
|
||||
if(%addToMissionGroup == true)
|
||||
MissionGroup.add(%newSGOObject);
|
||||
|
||||
return %newSGOObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<GameObjectAsset
|
||||
AssetName="ThirdPersonPlayerGameObjectAsset"
|
||||
gameObjectName="ThirdPersonPlayer"
|
||||
TAMLFilePath="scripts/server/gameObjects/ThirdPersonPlayerObject.taml"
|
||||
scriptFilePath="scripts/server/gameObjects/ThirdPersonPlayerObject.cs"/>
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
function ThirdPersonPlayerObject::onAdd(%this)
|
||||
{
|
||||
%this.turnRate = 0.3;
|
||||
|
||||
%this.phys = %this.getComponent("PlayerControllerComponent");
|
||||
%this.collision = %this.getComponent("CollisionComponent");
|
||||
%this.cam = %this.getComponent("CameraComponent");
|
||||
%this.camArm = %this.getComponent("CameraOrbiterComponent");
|
||||
%this.animation = %this.getComponent("AnimationComponent");
|
||||
%this.stateMachine = %this.getComponent("StateMachineComponent");
|
||||
%this.mesh = %this.getComponent("MeshComponent");
|
||||
|
||||
%this.stateMachine.forwardVector = 0;
|
||||
|
||||
%this.crouch = false;
|
||||
|
||||
%this.firstPerson = false;
|
||||
|
||||
%this.crouchSpeedMod = 0.5;
|
||||
|
||||
%this.aimOrbitDist = 1.5;
|
||||
%this.regularOrbitDist = 5;
|
||||
|
||||
%this.regularOrbitMaxPitch = 70;
|
||||
%this.regularOrbitMinPitch = -10;
|
||||
|
||||
%this.aimedMaxPitch = 90;
|
||||
%this.aimedMinPitch = -90;
|
||||
|
||||
%this.arms = SGOManager.spawn("FirstPersonArms", true);
|
||||
|
||||
%this.add(arms);
|
||||
|
||||
//%this.mesh.mountObject(%this.arms, "Eye");
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::onRemove(%this)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::moveVectorEvent(%this)
|
||||
{
|
||||
%moveVector = %this.getMoveVector();
|
||||
|
||||
// forward of the camera on the x-z plane
|
||||
%cameraForward = %this.cam.getForwardVector();
|
||||
|
||||
%cameraRight = %this.cam.getRightVector();
|
||||
|
||||
%moveVec = VectorAdd(VectorScale(%cameraRight, %moveVector.x), VectorScale(%cameraForward, %moveVector.y));
|
||||
|
||||
if(%this.aiming || %this.firstPerson)
|
||||
{
|
||||
%forMove = "0 0 0";
|
||||
|
||||
if(%moveVector.x != 0)
|
||||
{
|
||||
%this.phys.inputVelocity.x = %moveVector.x * 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
%this.phys.inputVelocity.x = 0;
|
||||
}
|
||||
|
||||
if(%moveVector.y != 0)
|
||||
{
|
||||
|
||||
%this.phys.inputVelocity.y = %moveVector.y * 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
%this.phys.inputVelocity.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(%moveVec.x == 0 && %moveVec.y == 0)
|
||||
{
|
||||
%this.phys.inputVelocity = "0 0 0";
|
||||
%this.stateMachine.forwardVector = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
%moveVec.z = 0;
|
||||
|
||||
%curForVec = %this.getForwardVector();
|
||||
|
||||
%newForVec = VectorLerp(%curForVec, %moveVec, %this.turnRate);
|
||||
|
||||
%this.setForwardVector(%newForVec);
|
||||
|
||||
%this.phys.inputVelocity.y = 10;
|
||||
|
||||
%this.stateMachine.forwardVector = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(%this.crouch)
|
||||
%this.phys.inputVelocity = VectorScale(%this.phys.inputVelocity, %this.crouchSpeedMod);
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::moveYawEvent(%this)
|
||||
{
|
||||
%moveRotation = %this.getMoveRotation();
|
||||
|
||||
%camOrb = %this.getComponent("CameraOrbiterComponent");
|
||||
|
||||
if(%this.aiming || %this.firstPerson)
|
||||
{
|
||||
%this.rotation.z += %moveRotation.z * 10;
|
||||
}
|
||||
|
||||
%camOrb.rotation.z += %moveRotation.z * 10;
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::movePitchEvent(%this)
|
||||
{
|
||||
%moveRotation = %this.getMoveRotation();
|
||||
|
||||
%camOrb = %this.getComponent("CameraOrbiterComponent");
|
||||
|
||||
%camOrb.rotation.x += %moveRotation.x * 10;
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::moveRollEvent(%this){}
|
||||
|
||||
function ThirdPersonPlayerObject::moveTriggerEvent(%this, %triggerNum, %triggerValue)
|
||||
{
|
||||
if(%triggerNum == 3 && %triggerValue)
|
||||
{
|
||||
if(%triggerValue)
|
||||
{
|
||||
%this.firstPerson = !%this.firstPerson;
|
||||
|
||||
if(%this.firstPerson)
|
||||
{
|
||||
%this.rotation.z = %this.cam.rotationOffset.z;
|
||||
%this.camArm.orbitDistance = 0;
|
||||
%this.camArm.maxPitchAngle = %this.aimedMaxPitch;
|
||||
%this.camArm.minPitchAngle = %this.aimedMinPitch;
|
||||
|
||||
%this.cam.positionOffset = "0 0 0";
|
||||
%this.cam.rotationOffset = "0 0 0";
|
||||
}
|
||||
else if(%this.aiming)
|
||||
{
|
||||
%this.camArm.orbitDistance = %this.aimOrbitDist;
|
||||
|
||||
%this.camArm.maxPitchAngle = %this.aimedMaxPitch;
|
||||
%this.camArm.minPitchAngle = %this.aimedMinPitch;
|
||||
}
|
||||
else
|
||||
{
|
||||
%this.camArm.orbitDistance = %this.regularOrbitDist;
|
||||
|
||||
%this.camArm.maxPitchAngle = %this.regularOrbitMaxPitch;
|
||||
%this.camArm.minPitchAngle = %this.regularOrbitMinPitch;
|
||||
}
|
||||
|
||||
commandToClient(localclientConnection, 'SetClientRenderShapeVisibility',
|
||||
localclientConnection.getGhostID(%this.getComponent("MeshComponent")), !%this.firstPerson);
|
||||
}
|
||||
}
|
||||
else if(%triggerNum == 2 && %triggerValue == true)
|
||||
{
|
||||
//get our best collision assuming up is 0 0 1
|
||||
%collisionAngle = %this.collision.getBestCollisionAngle("0 0 1");
|
||||
|
||||
if(%collisionAngle >= 80)
|
||||
{
|
||||
%surfaceNormal = %this.collision.getCollisionNormal(0);
|
||||
%jumpVector = VectorScale(%surfaceNormal, 200);
|
||||
echo("Jump surface Angle is at: " @ %surfaceNormal);
|
||||
|
||||
%this.phys.applyImpulse(%this.position, %jumpVector);
|
||||
%this.setForwardVector(%jumpVector);
|
||||
}
|
||||
else
|
||||
%this.phys.applyImpulse(%this.position, "0 0 300");
|
||||
}
|
||||
else if(%triggerNum == 4)
|
||||
{
|
||||
%this.crouch = %triggerValue;
|
||||
}
|
||||
else if(%triggerNum == 1)
|
||||
{
|
||||
%this.aiming = %triggerValue;
|
||||
|
||||
if(%this.aiming)
|
||||
{
|
||||
%this.rotation.z = %this.cam.rotationOffset.z;
|
||||
%this.camArm.orbitDistance = %this.aimOrbitDist;
|
||||
%this.camArm.maxPitchAngle = %this.aimedMaxPitch;
|
||||
%this.camArm.minPitchAngle = %this.aimedMinPitch;
|
||||
}
|
||||
else
|
||||
{
|
||||
%this.camArm.orbitDistance = %this.regularOrbitDist;
|
||||
%this.camArm.maxPitchAngle = %this.regularOrbitMaxPitch;
|
||||
%this.camArm.minPitchAngle = %this.regularOrbitMinPitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::onCollisionEvent(%this, %colObject, %colNormal, %colPoint, %colMatID, %velocity)
|
||||
{
|
||||
if(!%this.phys.isContacted())
|
||||
echo(%this @ " collided with " @ %colObject);
|
||||
}
|
||||
|
||||
function ThirdPersonPlayerObject::processTick(%this)
|
||||
{
|
||||
%moveVec = %this.getMoveVector();
|
||||
%bestFit = "";
|
||||
|
||||
if(%this.crouch)
|
||||
{
|
||||
if(%moveVec.x != 0 || %moveVec.y != 0)
|
||||
%bestFit = "Crouch_Forward";
|
||||
else
|
||||
%bestFit = "Crouch_Root";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(%moveVec.x != 0 || %moveVec.y != 0)
|
||||
%bestFit = "Run";
|
||||
else
|
||||
%bestFit = "Root";
|
||||
}
|
||||
|
||||
if(%this.animation.getThreadAnimation(0) !$= %bestFit)
|
||||
%this.animation.playThread(0, %bestFit);
|
||||
}
|
||||
|
||||
//Used for first person mode
|
||||
function clientCmdSetClientRenderShapeVisibility(%id, %visiblilty)
|
||||
{
|
||||
%localID = ServerConnection.resolveGhostID(%id);
|
||||
%localID.enabled = %visiblilty;
|
||||
}
|
||||
|
||||
function serverToClientObject( %serverObject )
|
||||
{
|
||||
assert( isObject( LocalClientConnection ), "serverToClientObject() - No local client connection found!" );
|
||||
assert( isObject( ServerConnection ), "serverToClientObject() - No server connection found!" );
|
||||
|
||||
%ghostId = LocalClientConnection.getGhostId( %serverObject );
|
||||
if ( %ghostId == -1 )
|
||||
return 0;
|
||||
|
||||
return ServerConnection.resolveGhostID( %ghostId );
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
<Entity
|
||||
scale="1 1 1"
|
||||
isSelectionEnabled="false"
|
||||
class="ThirdPersonPlayerObject"
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
position="0 0 0"
|
||||
rotation="0 0 0">
|
||||
<Component
|
||||
networked="false"
|
||||
enabled="true"
|
||||
class="ControlObjectComponent"
|
||||
clientOwner="1" />
|
||||
<CollisionComponent
|
||||
friendlyName="Collision(Component)"
|
||||
networked="false"
|
||||
enabled="true"
|
||||
collisionType="Bounds"
|
||||
LineOfSightType="Collision Mesh"
|
||||
decalType="Collision Mesh"
|
||||
CollisionMeshPrefix="Collision"
|
||||
BlockCollisions="true" />
|
||||
<PlayerControllerComponent
|
||||
componentType="Physics"
|
||||
friendlyName="Simple Physics"
|
||||
description="Simple physics behavior that allows gravity and impulses."
|
||||
networked="false"
|
||||
enabled="true"
|
||||
gravity="0 0 -9"
|
||||
velocity="0 0 0"
|
||||
isStatic="false" />
|
||||
<MeshComponent
|
||||
componentType="Render"
|
||||
friendlyName="Mesh Component"
|
||||
description="Causes the object to render a non-animating 3d shape using the file provided."
|
||||
networked="true"
|
||||
enabled="true"
|
||||
MeshAsset="Art:SoldierPlayer" />
|
||||
<Component
|
||||
networked="false"
|
||||
enabled="true"
|
||||
class="FPSControls" />
|
||||
<CameraComponent
|
||||
networked="false"
|
||||
enabled="true"
|
||||
FOV="80"
|
||||
MinFOV="5"
|
||||
MaxFOV="175"
|
||||
ScreenAspect="1024 768"
|
||||
targetNode="Eye"
|
||||
positionOffset="0 0 0"
|
||||
rotationOffset="0 0 0"
|
||||
useParentTransform="false" />
|
||||
<CameraOrbiterComponent
|
||||
orbitDistance="5"
|
||||
maxPitchAngle="70"
|
||||
minPitchAngle="-70"
|
||||
networked="false"
|
||||
enabled="true" />
|
||||
<AnimationComponent
|
||||
componentType="Render"
|
||||
friendlyName="Animation Component"
|
||||
description="An animation component"
|
||||
networked="true"
|
||||
enabled="true"/>
|
||||
<SpotLight
|
||||
range="10"
|
||||
innerAngle="40"
|
||||
outerAngle="45"
|
||||
isEnabled="true"
|
||||
color="1 1 1 1"
|
||||
brightness="1"
|
||||
castShadows="false"
|
||||
priority="1"
|
||||
animate="true"
|
||||
animationPeriod="1"
|
||||
animationPhase="1"
|
||||
flareScale="1"
|
||||
attenuationRatio="0 1 1"
|
||||
shadowType="Spot"
|
||||
texSize="512"
|
||||
overDarkFactor="2000 1000 500 100"
|
||||
shadowDistance="400"
|
||||
shadowSoftness="0.15"
|
||||
numSplits="1"
|
||||
logWeight="0.91"
|
||||
fadeStartDistance="0"
|
||||
lastSplitTerrainOnly="false"
|
||||
representedInLightmap="false"
|
||||
shadowDarkenColor="0 0 0 -1"
|
||||
includeLightmappedGeometryInShadow="false"
|
||||
position="0 0 1.6137"
|
||||
rotation="0 0 1 0"
|
||||
mountNode="-1"
|
||||
mountPos="0 0 1.5"
|
||||
mountRot="1 0 0 0"
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true" />
|
||||
</Entity>
|
||||
Loading…
Add table
Add a link
Reference in a new issue