Jump to content

Component runtime


Go to solution Solved by SpiderPig,

Recommended Posts

Posted

Placing this code in my main.lua ( before my main loop ) works fine. 

ok.png.f7254ff23740304b6ee03ea727fa411e.png

But if I move the code to my component's Start:Method()  nothing shows up.

I'm positive its something Im doing wrong.. but Im puzzled as to what it could be. I need a nudge ! :)

 

no.png.d8e022c1749883b706638aaa47290b55.png

function randomFloat(lower, greater)
    return lower + math.random()  * (greater - lower);
end

misc.lua: ( just a require-module with a bunch of home brew routines in it. )

 

    local amt = 10
    crows = {}
        for t=1, amt do 
            crows[t] = CreateBox(world)
            crows[t]:SetPosition(randomFloat(-2,0, 2.0), 2.0, randomFloat(-2.0, 2.0) )
        end
Posted

If this code is in a component, you probably want to get the world like this:

local world = self.enttty:GetWorld()

Maybe you need to pass that to a function, but that is a little better than relying on a global variable.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

These are the positions my World:Pick is giving me.. everyone of them are off by some weird amount.   I've got to quit  for a few days, I'm to frustrated to get anything accomplished.

bag.thumb.png.35d9889eaedf4d89d2981c3aa1ff2fd7.png

        for t=1, self.Amount do 

            local piv = CreatePivot(world) ; piv:SetHidden(true)
            local c = crow:Instantiate(world) ; c:SetPickMode(PICK_NONE)
            local pick_info = nil
 
            while pick_info == nil do 
                c:SetPosition(self.entity:GetPosition())
                c:Move(randomFloat( -(self.aabb.size.x/2),(self.aabb.size.x/2)) , self.aabb.size.y/2, randomFloat(-(self.aabb.size.z/2),(self.aabb.size.z/2)))
                piv:SetPosition(c:GetPosition())
                piv:Translate(0,-50,0)
                pick_info = world:Pick(c:GetPosition(true), piv:GetPosition(true), .25, true)
                if pick_info ~= nil then 
                    piv:SetPosition(pick_info.position)
                    c:SetPosition(pick_info.position)
                end
            end

            table.insert( self.crows, {
                piv = piv,
                mesh = c,
            })

	end

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...