thehankinator Posted May 1, 2016 Share Posted May 1, 2016 The script below Left arrow sets 90 degrees and RIght sets -90. Using the P key you can print the y rotation, it rarely achieves the requested rotation. Is there some kind of limitation for how big of an angle change I can put into SetInput? --Create a window window = Window:Create() context = Context:Create(window) world = World:Create() local camera = Camera:Create() camera:SetRotation(35,0,0) camera:Move(0,0,-8) local light = DirectionalLight:Create() light:SetRotation(35,35,0) --Enable navmesh debugging camera:SetDebugNavigationMode(true) --Create the ground local ground = Model:Box(10,1,10) ground:SetPosition(0,-0.5,0) ground:SetColor(0.0,0.25,0.0) --Create a shape local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10) ground:SetShape(shape) shape:Release() --Enable navigation obstacles ground:SetNavigationMode(true) --Create a character player = Pivot:Create() local visiblecapsule = Model:Cone(16, player) visiblecapsule:SetScale(1,2,1) visiblecapsule:SetPosition(0,1,0) visiblecapsule:SetRotation(90, 0 ,0) player:SetPosition(0,0,0) player:SetMass(1) player:SetPhysicsMode(Entity.CharacterPhysics) while not window:KeyHit(Key.Escape) do if window:Closed() then return false end Time:Update() if window:KeyHit(Key.Right) then player:SetInput(-90,0) end if window:KeyHit(Key.Left) then player:SetInput(90,0) end if window:KeyHit(Key.P) then System:Print(player:GetRotation(true).y) end world:Update() world:Render() context:Sync() end Quote Link to comment Share on other sites More sharing options...
Rick Posted May 1, 2016 Share Posted May 1, 2016 What if you set a variable for that and always call SetInput() with the variable vs calling it only when keys are hit. Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 1, 2016 Author Share Posted May 1, 2016 What if you set a variable for that and always call SetInput() with the variable vs calling it only when keys are hit. Same behavior, modded script below --Create a window window = Window:Create() context = Context:Create(window) world = World:Create() local camera = Camera:Create() camera:SetRotation(35,0,0) camera:Move(0,0,-8) local light = DirectionalLight:Create() light:SetRotation(35,35,0) --Enable navmesh debugging camera:SetDebugNavigationMode(true) --Create the ground local ground = Model:Box(10,1,10) ground:SetPosition(0,-0.5,0) ground:SetColor(0.0,0.25,0.0) --Create a shape local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10) ground:SetShape(shape) shape:Release() --Enable navigation obstacles ground:SetNavigationMode(true) --Create a character player = Pivot:Create() local visiblecapsule = Model:Cone(16, player) visiblecapsule:SetScale(1,2,1) visiblecapsule:SetPosition(0,1,0) visiblecapsule:SetRotation(90, 0 ,0) player:SetPosition(0,0,0) player:SetMass(1) player:SetPhysicsMode(Entity.CharacterPhysics) local roty = 0 while not window:KeyHit(Key.Escape) do if window:Closed() then return false end Time:Update() if window:KeyHit(Key.Right) then roty = -90 end if window:KeyHit(Key.Left) then roty = 90 end player:SetInput(roty,0) if window:KeyHit(Key.P) then System:Print(player:GetRotation(true).y) end world:Update() world:Render() context:Sync() end Quote Link to comment Share on other sites More sharing options...
Rick Posted May 1, 2016 Share Posted May 1, 2016 My memory is that SetInput() is for the rotation of the character controller which is a separate rotation than the model itself. So I would think player:GetRotation() is getting the model rotation and not the physics character controller rotation. I assume your character goes where you want it to direction wise, which would validate that. Then question I suppose is how to get the character controllers rotation value (but I guess you already have that with that variable right). Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 1, 2016 Author Share Posted May 1, 2016 My memory is that SetInput() is for the rotation of the character controller which is a separate rotation than the model itself. So I would think player:GetRotation() is getting the model rotation and not the physics character controller rotation. Isn't the model rotation tied to the character controller object? It must be because the model rotates properly when I use the navigation functions. Also the model is definitely not visibly rotating to +-90 even if the prints are not reliable. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 1, 2016 Share Posted May 1, 2016 What happens if you actually set the move variable in SetInput()? I might be remembering the old way of how this worked. In one version of LE they were separate. I haven't used the controller in 4 months or so in this version of LE so I don't recall. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 2, 2016 Share Posted May 2, 2016 What values are being printed? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
thehankinator Posted May 2, 2016 Author Share Posted May 2, 2016 What happens if you actually set the move variable in SetInput()? I might be remembering the old way of how this worked. In one version of LE they were separate. I haven't used the controller in 4 months or so in this version of LE so I don't recall. If I do SetInput(roty, 1) it turns the correct angle but the next frame I need to do SetInput(roty, 0) otherwise it keeps moving. Seems like a hack, or is this the desired behavior? What values are being printed? Below is the key I pressed and the value printed after pressing that key Left 50.4 Right 180 Left 169.2 Right -154.8 Left 151.2 Right -140.4 Left 129.6 Right -126 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 2, 2016 Share Posted May 2, 2016 You know it's going to gradually turn in the right direction, right? It won't instantly face that direction. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
thehankinator Posted May 2, 2016 Author Share Posted May 2, 2016 You know it's going to gradually turn in the right direction, right? It won't instantly face that direction. How could I make a character controller instantly face a direction? Quote Link to comment Share on other sites More sharing options...
Josh Posted May 2, 2016 Share Posted May 2, 2016 Why would you want to? Presently, it is hard-coded into the engine so that it will move at most 5 degrees per update. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
thehankinator Posted May 2, 2016 Author Share Posted May 2, 2016 Why would you want to? Presently, it is hard-coded into the engine so that it will move at most 5 degrees per update. I'm working on an action RPG something similar to Diablo style. When I click on the screen I want my character to immediately turn to the direction of the click and fire. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 2, 2016 Share Posted May 2, 2016 Okay, I am adding an extra parameter so you can specify the max rotation speed. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
thehankinator Posted May 2, 2016 Author Share Posted May 2, 2016 Okay, I am adding an extra parameter so you can specify the max rotation speed. Josh for president! Quote Link to comment Share on other sites More sharing options...
Josh Posted May 3, 2016 Share Posted May 3, 2016 (You will use 0 for instantaneous change in angle.) Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted May 3, 2016 Share Posted May 3, 2016 See docs update. Engine update will come tomorrow: http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetinput-r706 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
thehankinator Posted May 4, 2016 Author Share Posted May 4, 2016 See docs update. Engine update will come tomorrow: http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetinput-r706 Looks awesome, I think the other options you added will also be useful also. Thanks! Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 5, 2016 Author Share Posted May 5, 2016 I am having trouble getting the instantaneous change working. I've updated my original script (below) to set the new flags. Unfortunately I am not getting the instantaneous change I was expecting. I used default for everything except maxrotationspeed, I set it to 0. I also tried setting maxrotationspeed to 360 as well as detailed to true but that didn't help either. Did I misunderstand how to use this change? I am opt into beta. --Create a window window = Window:Create() context = Context:Create(window) world = World:Create() local camera = Camera:Create() camera:SetRotation(35,0,0) camera:Move(0,0,-8) local light = DirectionalLight:Create() light:SetRotation(35,35,0) --Enable navmesh debugging camera:SetDebugNavigationMode(true) --Create the ground local ground = Model:Box(10,1,10) ground:SetPosition(0,-0.5,0) ground:SetColor(0.0,0.25,0.0) --Create a shape local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10) ground:SetShape(shape) shape:Release() --Enable navigation obstacles ground:SetNavigationMode(true) --Create a character player = Pivot:Create() local visiblecapsule = Model:Cone(16, player) visiblecapsule:SetScale(1,2,1) visiblecapsule:SetPosition(0,1,0) visiblecapsule:SetRotation(90, 0 ,0) player:SetPosition(0,0,0) player:SetMass(1) player:SetPhysicsMode(Entity.CharacterPhysics) while not window:KeyHit(Key.Escape) do if window:Closed() then return false end Time:Update() if window:KeyHit(Key.Right) then player:SetInput(-90, 0, 0, 0, false, 1, 0.5, false, 0) end if window:KeyHit(Key.Left) then player:SetInput(90, 0, 0, 0, false, 1, 0.5, false, 0) end if window:KeyHit(Key.P) then System:Print(player:GetRotation(true).y) end world:Update() world:Render() context:Sync() end Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 12, 2016 Author Share Posted May 12, 2016 Any ideas? Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 12, 2016 Share Posted May 12, 2016 this seems to work ok - at least better than what the code above is showing for the player angle which for some reason is never close to the set angle: angle = 0 --defined before main loop ... ... p_rot = player:GetRotation(true) if window:KeyHit(Key.Right) then angle = 270 end if window:KeyHit(Key.Left) then angle = 90 end finalangle = Math:CurveAngle(angle, p_rot.y, 1.05)--setting division parameter to 1 or lower results in weird angles player:SetInput(finalangle, 0, 0, 0, false, 1, 0.5, false, 0.0) Other than that, I could only suggest you stick with a rigid body physics player and move/rotate using SetPosition/SetRotation. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
thehankinator Posted May 13, 2016 Author Share Posted May 13, 2016 this seems to work ok - at least better than what the code above is showing for the player angle which for some reason is never close to the set angle: angle = 0 --defined before main loop ... ... p_rot = player:GetRotation(true) if window:KeyHit(Key.Right) then angle = 270 end if window:KeyHit(Key.Left) then angle = 90 end finalangle = Math:CurveAngle(angle, p_rot.y, 1.05)--setting division parameter to 1 or lower results in weird angles player:SetInput(finalangle, 0, 0, 0, false, 1, 0.5, false, 0.0) Other than that, I could only suggest you stick with a rigid body physics player and move/rotate using SetPosition/SetRotation. I noticed my example used -90 and yours used 270 so I tried mine with 90/270 but still no luck. If I understand the update to SetInput correctly, I shouldn't need to play games with interpolating the angle to get the rotation to work. According to the updated reference for SetInput, setting maxrotationspeed to 0 should result in an instantaneous change to the requested angle. I might be misunderstanding the documentation but I think that my script should work. I'd love to use rigid body physics with SetRotation but then I'd have to implement my own pathing algorithm which seems like a lot of added work and complication when all that functionality already exists in LE it's just this one part that doesn't work and I think should. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted May 16, 2016 Share Posted May 16, 2016 Okay, I am adding an extra parameter so you can specify the max rotation speed. Can we please get this option for Follow and GoToPoint as well? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted May 17, 2016 Share Posted May 17, 2016 I'm just trying to avoid being able to do this. By the way, how do you get video to be inline? I thought it was the [ media ] tag (without spaces). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.