Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "/scripts/vec2.lua"
- function init()
- self.holdingJump = false
- self.active = false
- self.flightControlForce = config.getParameter("flightControlForce")
- end
- function input(args)
- if args.moves["jump"] and mcontroller.jumping() then
- self.holdingJump = true
- elseif not args.moves["jump"] then
- self.holdingJump = false
- end
- if args.moves["jump"] and not mcontroller.canJump() and not self.holdingJump then
- return "angelflight"
- else
- return nil
- end
- end
- function update(args)
- local action = input(args)
- local energyUsagePerSecond = config.getParameter("energyUsagePerSecond")
- local hDirection = args.moves["left"] and -1 or (args.moves["right"] and 1 or 0)
- local vDirection = args.moves["down"] and -1 or (args.moves["up"] and 1 or 0)
- local energyOff = (hDirection == 0 and vDirection == 0) and 0 or 1
- if action == "angelflight" and (not status.statPositive("activeMovementAbilities")) and status.overConsumeResource("energy", energyUsagePerSecond * args.dt * energyOff) then
- animator.setAnimationState("wings", "fly")
- --WING FACING DIRECTION
- if mcontroller.facingDirection() == -1 then
- --LOOKING LEFT
- animator.setGlobalTag("facingDirection", "left");
- else
- --LOOKING RIGHT
- animator.setGlobalTag("facingDirection", "right");
- end
- local maxSpeed = math.min(20^0.6 + 25, 45)
- local angle = (hDirection ~= 0 or vDirection ~= 0) and vec2.angle({hDirection, vDirection}) or false
- local velocity = angle and vec2.withAngle(angle, maxSpeed) or {0,0}
- mcontroller.controlApproachVelocity(velocity, self.flightControlForce)
- if vDirection == 0 then mcontroller.controlApproachYVelocity(0, self.flightControlForce) end
- if not self.active then
- end
- self.active = true
- else
- if self.active then
- mcontroller.controlApproachVelocity({0,0}, self.flightControlForce * 10)
- status.setResourceLocked("energy", energyOff == 0)
- end
- self.active = false
- status.setResourceLocked("energy", false)
- animator.setAnimationState("wings", "off")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment