Jump to content

Entity::SetInput, maxrotationspeed


psychoanima
 Share

Recommended Posts

Honestly, I do not think that has been fully implemented as I never saw any difference in behavior from a max rotation speed between 5000 or 0.0005. What you can do is control how fast the angle value is changed to the final amount.

 

example:

angle = player:GetRotation(true).y --defined before main loop

move = 0

strafe = 0

jump = 0

crouch = false

maxaccel = 1

maxdecel = 0.5

detailed = false

maxrotationspeed = 0.5

..

..

--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, 10) --decrease step to quicken rotation

player:SetInput(finalangle,move,strafe,jump,crouch,maxaccel,maxdecel,detailed,maxrotationspeed)

  • Upvote 1

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

Honestly, I do not think that has been fully implemented as I never saw any difference in behavior from a max rotation speed between 5000 or 0.0005. What you can do is control how fast the angle value is changed to the final amount.

 

example:

angle = player:GetRotation(true).y --defined before main loop

move = 0

strafe = 0

jump = 0

crouch = false

maxaccel = 1

maxdecel = 0.5

detailed = false

maxrotationspeed = 0.5

..

..

--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, 10) --decrease step to quicken rotation

player:SetInput(finalangle,move,strafe,jump,crouch,maxaccel,maxdecel,detailed,maxrotationspeed)

 

 

That's really cool idea for rotation, thanks!

 

Do you think it can be easily implemented with the script bellow:

 

http://www.leadwerks.com/werkspace/topic/12651-2d-platformer-player-script-example/page__hl__platformer

 

(I am using the same logic like in function Script:UpdatePhysics() )

Link to comment
Share on other sites

Math:CurveAngle() works perfect for my rotation need.

 

Now I have another problem. My character is moving on X and Z axis but needs to stay locked on Z and to move only on X.

 

 

I read in one post this method for locking:

 

(in function Script:Start())

vec = self.entity:GetPosition()]

 

&

 

( in function Script:UpdateWorld())

self.entity:PhysicsSetPosition(0,0,vec.z)

 

 

 

but nothing is changing in the viewer, it's still floating on Z

Link to comment
Share on other sites

You should be able to just set the position (using entity:SetPosition) to align on whatever value for Z that you would want. Just perform it prior to the SetInput().

 

An example on one way to perform this:

window = Window:Create("Example", 0, 0, 800, 600,257)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

camera:SetDebugPhysicsMode(true)

camera:SetPosition(0,6,0)

camera:SetRotation(90,0,0)

light = DirectionalLight:Create()

light:SetRotation(35,35,0)

 

ground = Model:Box(10,1,10)

ground:SetPosition(0,-0.5,0)

ground:SetColor(0.6,1,0.6)

shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)

ground:SetShape(shape)

shape:Release()

ground:SetCollisionType(Collision.Scene)

 

player = Model:Load("Models/characters/crawler/crawler.mdl")

player:SetCharacterControllerAngle(180)

player:SetPhysicsMode(Entity.CharacterPhysics)

player:SetCollisionType(Collision.Character)

player:SetPosition(0,0,2.5)

player:SetMass(10)

 

angle = player:GetRotation(true).y

Zpos = player:GetPosition(true).z

move = 0

 

while not window:KeyHit(Key.Escape) do

if window:Closed() then return false end

 

move = 0

if window:KeyDown(Key.Left) then

angle = 90

move = 3

end

if window:KeyDown(Key.Right) then

angle = -90

move = 3

end

 

p_pos = player:GetPosition(true)

if math.abs(p_pos.z-Zpos)>0.01 then player:SetPosition(p_pos.x,p_pos.y,Zpos) end

 

p_rot = player:GetRotation(true)

finalangle = Math:CurveAngle(angle, p_rot.y, 3)

player:SetInput(finalangle,move,0,0,false,1,0.5,false,5.0)

 

Time:Update()

world:Update()

world:Render()

 

context:SetBlendMode(Blend.Alpha)

context:DrawText("Press LEFT/RIGHT arrow keys to move",2,2)

context:DrawText(string.format("Player Z Position: %.1f",p_pos.z),2,22)

context:DrawText(string.format("Player Angle: %.1f",player:GetRotation(true).y),2,42)

context:SetBlendMode(Blend.Solid)

context:Sync(true)

end

  • Upvote 1

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

p_pos = player:GetPosition(true)

if math.abs(p_pos.z-Zpos)>0.01 then player:SetPosition(p_pos.x,p_pos.y,Zpos) end

 

 

 

Thanks!

 

That solved my problem!

 

 

However, because my camera is attached to the character, during rotation camera shakes.

 

I solve that like this:

 

 

function Script:Start()

self.camera = Camera:Create()

self.cameraZ = self.camera:GetPosition().z

self:UpdateCamera()

end

 

 

function Script:UpdateCamera()

self.camera:SetRotation(35,0,0)

self.camera:SetPosition(self.entity:GetPosition().x,self.entity:GetPosition().y, self.cameraZ )

self.camera:Move(0,0,-120)

 

end

 

 

 

I don't know if there is easier or more clean way to do this, but it works. smile.png

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...