Time for action - changing the teleporter entity to execute the C++ code
First, we need to change the lua script. We want to change the function Teleporter:OnUsed to call our C++ function instead of doing the calculation in Lua.
This is pretty easy. Change the function as shown below:
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); --call the scriptbind function user.actor:TeleportTo(vTargetPos); end
Save your changes of Teleporter.lua.
With the use of user.actor:<function>, we can call all the
Scriptbind
functions that are implemented in ScriptBind_Actor...