Scripts / Player standing on (or in) an entity

Author
Message
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 8th Jul 2016 22:46
So you have an entity, maybe a square or rectangular platform (or just a bit of floor somewhere, and you want to know if the player is standing on it.

Ent = g_Entity[e] -- the entity we need to test against

local DX, DY, DZ = g_PlayerPosX - Ent.x, g_PlayerPosY - Ent.y, g_PlayerPosZ - Ent.z
local angle = math.atan(DX, DZ) - math.rad(Ent.angley)
local hyp = math.sqrt(DX*DX + DZ*DZ)
local NX, NZ = math.sin(angle) * hyp, math.cos(angle) * hyp

Now simply check DY, NX and NZ against the entity size, assuming the entities origin is in the centre (most are) and is W wide H high and L long:

if (DY > H and DY < H + 50 and DX > -W/2 and DX < W/2 and DZ > -L/2 and DZ < L/2) then

-- Player is on the entity
end

Been there, done that, got all the T-Shirts!
PM
Tauren
8
Years of Service
User Offline
Joined: 25th Jun 2015
Playing: PUBG,Conan Exiles,WoW,HoMM III,MoO 2,Master of Orion 2016
Posted: 9th Jul 2016 02:57
Big thanks, AmenMoses! I was just thinking how to do such a thing.
PM

Login to post a reply

Server time is: 2024-05-03 23:23:29
Your offset time is: 2024-05-03 23:23:29