Right now, I am polishing off the animation sequences for my character and I am faced with two final problems.
One, my character skids when jumping and then pressing and holding the left or right button.
https://www.youtube.com/watch?v=h00vTu_82bM
Two, if the character jumps and then another button is pressed the animation will stop mid-way.
https://www.youtube.com/watch?v=ciIdq_0_dtY&feature=youtu.be
I am not sure where to place the sequence-changing code in these two situations.
Sorry, I reposted this topic but was not getting any replies (except for Brent’s). I know this goes against community guidelines, but I have to present at least a prototype of the first scene without any bugs.
Please advise on these two issues, thanks!
And of course the code:
local function jump() local vx, vy = anim:getLinearVelocity() local stopped = (vy^2 \<= 0.5) if stopped == true then local jumpVecY = -13 anim.gravityScale = 1 anim:applyLinearImpulse(0, jumpVecY \* anim.mass, anim.x, anim.y ) anim:setSequence("jump") anim:play() end end local function walk(xScale) local vx, vy = anim:getLinearVelocity() local stopped = (vy^2 \<= 0.5) if stopped == true then anim:setLinearVelocity(xScale \* 150, 0) anim.xScale = xScale anim:setSequence("walk") anim:play() end end local function idle() anim:setLinearVelocity(0, 0) anim:setSequence("idle") anim:play() anim.xScale = anim.xScale end local function simulatorControl(event) if event.phase == "down" then if event.keyName == "space" then jump() end end end local function makeControls(self, event) if event.phase == "began" then if self.name == "left" then walk(-1) elseif self.name == "right" then walk(1) elseif self.name == "jump" then jump() end elseif event.phase == "ended" or event.phase == "moved" then idle() end end
I really don’t want to make a bad impression by having errors…
Thanks again!