Time for action - making the teleporter usable
In order to make any object intractable, we have to add two functions to our lua code:
The function
IsUsable
The function
OnUsed
Let's implement these functions. We need to extend the
Teleporter.lua
script with some more functions:--tell the engine that we can interact with this entity function Teleporter:IsUsable(user) return 1; end ---------------------------------------- function Teleporter:OnUsed(user) --check „user" being valid if (not user) then return 0; end --compute target position from current position + teleport direction local vCurPos = {}; user:GetWorldPos(vCurPos); local vTargetDir = {}; --assign a temp vector as targetDir „type" vTargetDir.x = self.Properties.teleportDirX; vTargetDir.y = self.Properties.teleportDirY; vTargetDir.z = self.Properties.teleportDirZ; local vTargetPos = vecAdd(vCurPos, vTargetDir); --set target position on player entity user:SetWorldPos(vTargetPos); end
The function
IsUsable...