Jump to content

Recommended Posts

Hello,

 

I am a new modder and new to forums in general, and would like to ask you guys a couple of simple questions.

 

First question: Can I track rotation(q&e) through an already built in value like north, south, east, west or 90,180, 270, 360 degrees? Or do I have to write something to calculate the direction and amount of turns manually?

 

Second question: How do I set a key to an action; say i wanted to have a key to set the time to day?

 

 

Thanks

@Electroshockist, you can use the following code to do #2:

 

TheInput:AddKeyHandler(function(key, down)

if key == GLOBAL.KEY_Z and not down then

    -- SET THE PHASE TO DAY.

end

end)

 

You will need to add it somewhere in the prefab such as the following:

 
local function ControlsPostConstruct(inst)
inst.handler_example = GLOBAL.TheInput:AddKeyHandler(function(key, down)

if key == GLOBAL.KEY_Z and not down then

    -- SET THE PHASE TO DAY.

end

end )
end
AddClassPostConstruct("widgets/controls", ControlsPostConstruct)

 

@Electroshockist

 

For the first question.

 

This is how the compass prefab handles it.

local function GetDirection()            local heading = TheCamera:GetHeading()--inst.Transform:GetRotation()     local dirs =     {        N=0, S=180,        NE=45, E=90, SE=135,        NW=-45, W=-90, SW=-135,     }    local dir, closest_diff = nil, nil    for k,v in pairs(dirs) do        local diff = math.abs(anglediff(heading, v))        if not dir or diff < closest_diff then            dir, closest_diff = k, diff        end    end    return dirend

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...