How does worltolocal work?

How does worltolocal work?
:confused:
I tried this but it didn’t work:

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)
function ENT:Initialize()
self.Entity:SetModel(“models/props_lab/blastdoor001c.mdl”)
self.Entity:SetMaterial(“phoenix_storms/stripes.vmt”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
end
function OyFekOff( ply, ent )
if ent:GetClass() == “entity_spikestrip” then return false end
end

function ENT:PhysicsCollide( data, phys )
local colidedent = data.HitEntity
if colidedent:GetClass() == “prop_ragdoll” then
colidedent:Remove()
colidedent:EmitSound( “items/ammocrate_open.wav” )
local body = ents.Create(“entity_bodybox”)
local spawnmid = self:WorldToLocal(self:GetPos())
body:SetPos(spawnmid)
body:Spawn()
print (self:GetPos())
print (body:GetPos())
end
end

[editline]27th November 2016[/editline]

[LUA]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)
function ENT:Initialize()
self.Entity:SetModel(“models/props_lab/blastdoor001c.mdl”)
self.Entity:SetMaterial(“phoenix_storms/stripes.vmt”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
end
function OyFekOff( ply, ent )
if ent:GetClass() == “entity_spikestrip” then return false end
end

function ENT:PhysicsCollide( data, phys )
local colidedent = data.HitEntity
if colidedent:GetClass() == “prop_ragdoll” then
colidedent:Remove()
colidedent:EmitSound( “items/ammocrate_open.wav” )
local body = ents.Create(“entity_bodybox”)
local spawnmid = self:WorldToLocal(self:GetPos())
body:SetPos(spawnmid)
body:Spawn()
print (self:GetPos())
print (body:GetPos())
end
end [/LUA]

Have you read the wiki?

WorldToLocal

Entity:WorldToLocal

Yes. im trying to do the second wiki page you sent.
I got a update tho. I got the WorldToLocal to work. But it won’t spawn where i want it to:

Console:[LUA]
Changing collision rules within a callback is likely to cause crashes!
Changing collision rules within a callback is likely to cause crashes!
Self.Entity 1506.898682 -878.024292 -199.145920
BoxSpawn 201.288300 -1128.609619 -1329.305298[/LUA]
[LUA]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)
function ENT:Initialize()
self.Entity:SetModel(“models/props_lab/blastdoor001c.mdl”)
self.Entity:SetMaterial(“phoenix_storms/stripes.vmt”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
end

function ENT:PhysicsCollide( data, phys )
local colidedent = data.HitEntity
if colidedent:GetClass() == “prop_ragdoll” then
colidedent:Remove()
colidedent:EmitSound( “items/ammocrate_open.wav” )
local body = ents.Create(“entity_bodybox”)
local spawnmid = self:WorldToLocal(body:GetPos())
local spawnmidbox = body:WorldToLocal(spawnmid)
body:SetPos(spawnmid)
body:Spawn()
print (“Self.Entity”,self:GetPos())
print (“BoxSpawn”,body:GetPos())
end
end
[/LUA]

[editline]27th November 2016[/editline]

Spawns the at the worldpos not the local pos.

I don’t think you need WorldToLocal at all.

[lua]function ENT:PhysicsCollide( data, phys )
local colidedent = data.HitEntity
if colidedent:GetClass() == “prop_ragdoll” then
local bodypos = colidedent:GetPos()
colidedent:Remove()
– …
body:SetPos(bodypos)
– …
end
end[/lua]

[editline]27th November 2016[/editline]

In order to understand what WorldToLocal and LocalToWorld do, you’ll first have to understand vectors, which isn’t TOO complicated but I don’t have time to explain it properly. Look up some vector lessons on youtube.