Jump to content

Animation not playing when running to the right.


Megalocerous
 Share

Recommended Posts

Hey guys,

 

Not sure if anyone can help me out. I have a weird issue right now where the running animation for the character I am using does not play when I am running to the right. However the idle animation seems to run no matter which direction I am facing.

 

 

Script.movespeed = 5 --float
Script.cameradistance = 40 --float
Script.camerazoom = 8 --float
Script.orthographicseffect = 1 --float "Flatness"
Script.camerarange = 10 --float
Script.jump = 15 --int
Script.ismoving = false --bool
Script.isjumping = false --bool

--Animation variables
Script.animationspeed = 1.0 --float
Script.idlesequence = 0 --int
Script.runsequence = 0 --int
Script.jumpsequence = 0 --int
function Script:Start()
self.playerangle = -90.0
self.camera = Camera:Create()
self.entity:SetPhysicsMode(Entity.CharacterPhysics)
self.camera:SetRotation(0,0,0)
self.camera:SetZoom(self.camerazoom*self.orthographicseffect)
self.camera:SetRange(self.cameradistance*self.orthographicseffect-self.camerarange, self.cameradistance*self.orthographicseffect+self.camerarange)


if self.entity:GetMass() == 0 then self.entity:SetMass(10) end

end

function Script:UpdateWorld()
--Update the camera
self.camera:SetPosition(self.entity:GetPosition())
self.camera:Move(0,1.8/2,-self.cameradistance*self.orthographicseffect)


end

function Script:UpdatePhysics()

local window = Window:GetCurrent()
local move = 0
local jump = 0

--Set the players direction if they move left or right
if window:KeyDown(Key.D) then

self.playerangle = -90.0
self.ismoving = true
move = move - self.movespeed

else
self.ismoving = false
end

if window:KeyDown(Key.A) then

self.playerangle = 90.0
self.ismoving = true
move = move - self.movespeed


else
self.ismoving = false
end


--Set the players jump if space is hit
if window:KeyHit(Key.Space) then

jump = self.jump

end
self.entity:SetInput(self.playerangle,move,0,jump,false,1.0,1.0,true)
end

function Script:Draw()
local t = Time:GetCurrent()
if self.ismoving == true then
self.entity:SetAnimationFrame(t/100.0*self.animationspeed,1,self.runsequence)
elseif self.ismoving == false then
self.entity:SetAnimationFrame(t/100.0*self.animationspeed,1,self.idlesequence)
end

end

Link to comment
Share on other sites

The else for key A was always being called when key D was down.

Simple fix:

 

if window:KeyDown(Key.D) then
 self.playerangle = -90.0
 self.ismoving = true
 move = move - self.movespeed
elseif window:KeyDown(Key.A) then
 self.playerangle = 90.0
 self.ismoving = true
 move = move - self.movespeed
else
 self.ismoving = false
end

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

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