Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,58 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local AddPhysicsImpulse =
{
Properties =
{
IncomingGameplayEventName = "",
IsRelative = {default=true, description="When true, the impulse will be applied relative to the entity's transform"},
ImpulseScale = {default=1.0, description="This will scale the vector before sending it"},
},
}
function AddPhysicsImpulse:OnActivate()
local gameplayBusId = GameplayNotificationId(self.entityId, self.Properties.IncomingGameplayEventName, "Vector3")
self.gameplayBus = GameplayNotificationBus.Connect(self, gameplayBusId)
end
function AddPhysicsImpulse:AddImpulse(vectorValue)
if self.Properties.IsRelative then
local localTM = TransformBus.Event.GetWorldTM(self.entityId)
localTM:SetTranslation(Vector3(0,0,0))
localTM:ExtractScale()
PhysicsComponentRequestBus.Event.AddImpulse(self.entityId, localTM * (vectorValue*self.Properties.ImpulseScale))
else
PhysicsComponentRequestBus.Event.AddImpulse(self.entityId, vectorValue*self.Properties.ImpulseScale)
end
end
function AddPhysicsImpulse:OnEventBegin(vectorValue)
self:AddImpulse(vectorValue)
end
function AddPhysicsImpulse:OnEventUpdating(vectorValue)
self:AddImpulse(vectorValue)
end
function AddPhysicsImpulse:OnEventEnd(vectorValue)
self:AddImpulse(vectorValue)
end
function AddPhysicsImpulse:OnDeactivate()
self.gameplayBus:Disconnect()
end
return AddPhysicsImpulse
@@ -0,0 +1,88 @@
--
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
local EntityLookAt =
{
Properties =
{
EntityTargetToFace = {default=EntityId()},
Advanced = {default="Edit this script to face a different axis towards the target"},
},
Handlers =
{
MyTransform = {},
TargetTransform = {},
}
}
function EntityLookAt:OnActivate()
if self.Properties.EntityTargetToFace:IsValid() then
-- cache properties
local myTM = TransformBus.Event.GetWorldTM(self.entityId)
self.myPos = myTM:GetPosition()
self.targetPos = TransformBus.Event.GetWorldTranslation(self.Properties.EntityTargetToFace)
self.myScale = myTM:RetrieveScale()
self.readyForRotation = true
--attach handlers
self.myTransform = TransformNotificationBus.Connect(self.Handlers.MyTransform, self.entityId)
self.targetTransform = TransformNotificationBus.Connect(self.Handlers.TargetTransform, self.Properties.EntityTargetToFace)
self.Handlers.MyTransform.parent = self
self.Handlers.TargetTransform.parent = self
self:UpdateFacing()
end
end
function EntityLookAt.Handlers.TargetTransform:OnTransformChanged(localTM, worldTM)
local distance = self.parent.targetPos - worldTM:GetPosition()
-- if our target has moved, Update our facing
if not distance:IsZero(0.0001) then
self.parent.targetPos = worldTM:GetPosition()
self.parent:UpdateFacing()
end
end
function EntityLookAt.Handlers.MyTransform:OnTransformChanged(localTM, worldTM)
-- cache the scale
self.parent.myScale = worldTM:RetrieveScale()
local distance = self.parent.myPos - worldTM:GetPosition()
-- if we've moved then update our facing
if self.parent.readyForRotation then
self.parent.myPos = worldTM:GetPosition()
self.parent:UpdateFacing()
end
end
function EntityLookAt:UpdateFacing()
self.readyForRotation = false
-- you can use Model Space relative AxisType's of
-- YPositive : face directly at targetPos,
-- YNegative : face directly away from targetPos,
-- XPositive : "right shoulder" faces targetPos,
-- XNegative : "left shoulder" faces targetPos,
-- ZPositive : top faces targetPos
-- ZNegative : bottom faces targetPos
self.axisToFaceAtTarget = AxisType.YPositive
local tm = MathUtils.CreateLookAt(self.myPos, self.targetPos, self.axisToFaceAtTarget)
tm:MultiplyByScale(self.myScale)
TransformBus.Event.SetWorldTM(self.entityId, tm)
self.readyForRotation = true
end
function EntityLookAt:OnDeactivate()
self.Handlers.MyTransform = {}
self.Handlers.TargetTransform = {}
self.myTransform = nil
self.targetTransform = nil
end
return EntityLookAt
@@ -0,0 +1,58 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MoveEntity =
{
Properties =
{
IncomingGameplayEventName = "",
IsRelative = {default=true, description="When true, the velocity will be applied relative to the entity's transform"},
VelocityScale = {default=1.0, description="This will scale the vector before sending it"},
},
}
function MoveEntity:OnActivate()
local gameplayBusId = GameplayNotificationId(self.entityId, self.Properties.IncomingGameplayEventName, "Vector3")
self.gameplayBus = GameplayNotificationBus.Connect(self, gameplayBusId)
end
function MoveEntity:SetVelocity(vectorValue)
if self.Properties.IsRelative then
local localTM = TransformBus.Event.GetWorldTM(self.entityId)
localTM:SetTranslation(Vector3(0,0,0))
localTM:ExtractScale()
PhysicsComponentRequestBus.Event.SetVelocity(self.entityId, localTM * (vectorValue*self.Properties.VelocityScale))
else
PhysicsComponentRequestBus.Event.SetVelocity(self.entityId, vectorValue*self.Properties.VelocityScale)
end
end
function MoveEntity:OnEventBegin(vectorValue)
self:SetVelocity(vectorValue)
end
function MoveEntity:OnEventUpdating(vectorValue)
self:SetVelocity(vectorValue)
end
function MoveEntity:OnEventEnd(vectorValue)
self:SetVelocity(vectorValue)
end
function MoveEntity:OnDeactivate()
self.gameplayBus:Disconnect()
end
return MoveEntity
@@ -0,0 +1,68 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local RotateEntity =
{
Properties =
{
IncomingGameplayEventName = "",
AxisOfRotation = {default=Vector3(0,0,1), description="The axis to rotate around"},
IsRelative = {default=true, description="When true, the entity's transform will transform the AxisOfRotation"},
RotationSpeed = {default=60, description="Degrees per second."},
},
}
function RotateEntity:OnActivate()
local gameplayBusId = GameplayNotificationId(self.entityId, self.Properties.IncomingGameplayEventName, "float")
self.gameplayBus = GameplayNotificationBus.Connect(self, gameplayBusId)
end
function RotateEntity:ApplyRotation(floatValue)
local axisOfRotation = self.Properties.AxisOfRotation:GetNormalized()
local localTM = TransformBus.Event.GetWorldTM(self.entityId)
local translation = localTM:GetTranslation()
localTM:SetTranslation(Vector3(0,0,0))
local scale = localTM:ExtractScale()
if not self.Properties.IsRelative then
axisOfRotation = axisOfRotation * localTM
end
local dt = TickRequestBus.Broadcast.GetTickDeltaTime()
local rotationAmount = floatValue * dt * Math.DegToRad(self.Properties.RotationSpeed)
local finalTM = localTM * Transform.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(axisOfRotation, rotationAmount):GetNormalized())
finalTM:SetPosition(translation)
finalTM:MultiplyByScale(scale)
TransformBus.Event.SetWorldTM(self.entityId, finalTM)
end
function RotateEntity:OnEventBegin(floatValue)
self:ApplyRotation(floatValue)
end
function RotateEntity:OnEventUpdating(floatValue)
self:ApplyRotation(floatValue)
end
function RotateEntity:OnEventEnd(floatValue)
self:ApplyRotation(floatValue)
end
function RotateEntity:OnDeactivate()
self.gameplayBus:Disconnect()
end
return RotateEntity