❄️🎁⛄ The Winter Games Tournament is Live! 🎄🎅❄️
Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

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.

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