Electroshockist Posted January 21, 2015 Share Posted January 21, 2015 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 Link to comment https://forums.kleientertainment.com/forums/topic/49465-help-with-rotation-tracking-and-adding-keybinds/ Share on other sites More sharing options...
Kzisor Posted January 21, 2015 Share Posted January 21, 2015 @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.endend) 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.endend )endAddClassPostConstruct("widgets/controls", ControlsPostConstruct) Link to comment https://forums.kleientertainment.com/forums/topic/49465-help-with-rotation-tracking-and-adding-keybinds/#findComment-604233 Share on other sites More sharing options...
Electroshockist Posted January 21, 2015 Author Share Posted January 21, 2015 @ Kzisorthanks Link to comment https://forums.kleientertainment.com/forums/topic/49465-help-with-rotation-tracking-and-adding-keybinds/#findComment-604413 Share on other sites More sharing options...
Blueberrys Posted January 26, 2015 Share Posted January 26, 2015 @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 Link to comment https://forums.kleientertainment.com/forums/topic/49465-help-with-rotation-tracking-and-adding-keybinds/#findComment-606093 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now