Megalocerous Posted July 24, 2016 Share Posted July 24, 2016 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 Quote Link to comment Share on other sites More sharing options...
Jazz Posted July 24, 2016 Share Posted July 24, 2016 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 Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
Megalocerous Posted July 25, 2016 Author Share Posted July 25, 2016 Thanks so much SGB! I completely overlooked that when I was reading through my script before. It is working fine now. Thanks again really appreciate it! 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.