Jump to content

Getting Object Position?(Confused and Might need assistance)


Recommended Posts

Ok so I Took notice of 'get random position':

local function getrandomposition(caster)
 local ground = TheWorld
 local centers = {}
   for i, node in ipairs(ground.topology.nodes) do
        if ground.Map:IsPassableAtPoint(node.x, 0, node.y) then
            table.insert(centers, {x = node.x, z = node.y})
        end
    end 
    if #centers > 0 then
        local pos = centers[math.random(#centers)]
        return pos.x, 0, pos.z
    else
        return caster:GetPosition()
    end
end

However I'm trying to get the position of an object stead so I can make that once an object is used, it spawns it at the location of the object. I have no idea how to do that, attempts on it resulted in the object not spawning or crashing.

Is there any way to replace the 'math.random' ? if not is there anyway to get the position of an object through x,y,z ?
 

Link to comment
Share on other sites

Let 'A' be the already placed entity, and 'B' be the one you want to place.

local x,y,z = A.Transform:GetWorldPosition()
A:Remove()
local B = SpawnPrefab("bob")
B.Transform:SetPosition(x,y,z)

Or are you trying to find all entities at a position?

local ents = TheSim:FindEntities(x, y, z)
for _,ent in ipairs(ents)
do
    if ent.prefab == "bob_spawner"
    then
        local x,y,z = ent.Transform:GetWorldPosition()
        ent:Remove()
        local B = SpawnPrefab("bob")
        B.Transform:SetPosition(x, y, z)
    end
end

 

Or are you trying to hook into an already made function from the core game files?  If so, then post file names/line numbers/etc with what you're trying to hook.

  • Thanks 1
Link to comment
Share on other sites

On 4/28/2019 at 11:47 AM, CarlZalph said:

Let 'A' be the already placed entity, and 'B' be the one you want to place.


local x,y,z = A.Transform:GetWorldPosition()
A:Remove()
local B = SpawnPrefab("bob")
B.Transform:SetPosition(x,y,z)

Or are you trying to find all entities at a position?


local ents = TheSim:FindEntities(x, y, z)
for _,ent in ipairs(ents)
do
    if ent.prefab == "bob_spawner"
    then
        local x,y,z = ent.Transform:GetWorldPosition()
        ent:Remove()
        local B = SpawnPrefab("bob")
        B.Transform:SetPosition(x, y, z)
    end
end

 

Or are you trying to hook into an already made function from the core game files?  If so, then post file names/line numbers/etc with what you're trying to hook.

Sorry for taking so long to reply, lots of stuff mid week. I'll give a shot on what you provided here.

To iterate better, looking at how I worded myself. What I'm basically trying to do is a gun that shoots portals. Basically when it shoots a portal open, it should automatically spawn an exit portal at the position of another object that remains in one place.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...