Jump to content

Recommended Posts

I saw a forum post where a person was making a character which dropped logs with a 50/50 chance when they were hit. Link: https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/

My character is a grass gekko, and I want them to drop grass sometimes upon being hit. I copied the code to see whether it would work, but when my character gets hit there is an error message, which I've attached. If anyone could make sense of this and help me it'd mean the world, thanks!

error.PNG

If you read the comments after the code-block, they solve the problem in the thread. The error even points out that the function is misspelled (by telling you it doesn't exist, when we know all entities are guaranteed to have a SetPosition() function).

Edited by Ultroman

Thanks, I fixed the problem but now it says that "variable 'projectile' is not declared" in the error.

This is the code for it:

inst:ListenForEvent("attacked", function(inst)
    inst:DoTaskInTime(0, function(inst)
        if math.random() <= .5 then
            local wood = SpawnPrefab("log")
            wood.Transform:SetPosition(inst.Transform:GetWorldPosition())
            
            if wood.Physics ~= nil then
                local x, y, z = wood.Transform:GetWorldPosition()
                wood.Physics:Teleport(x, .3, z)

                local angle = (math.random() * 20 - 10) * DEGREES
                angle = angle + math.random() * 2 * PI
                
                local speed = projectile and 2 + math.random() or 3 + math.random() * 2
                wood.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed)
            end
        end
    end)
end)

 

If anyone could help again that would be great, thanks

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
×
  • Create New...