I am trying to get a jetpack hover working similar to mario sunshine's hover ability. I can't seem to get it to keep hover after holding down the button for six seconds. Any advice is very much appreciated.
Here is my move script:
extends PlayerState
export var maxspeed: = 25.0
export var movespeed: = 25.0
export var gravity: = -80.0
export var jumpimpulse: = 25.0
export var attack: = 10.0
export var hoverimpulse: = 10.0
var velocity: = Vector3.ZERO
func unhandledinput(event: InputEvent) -> void:
if event.isactionpressed("jump"):
_statemachine.transitionto("Move/Air", { velocity = velocity, jumpimpulse = jumpimpulse })
elif event.isactionpressed("attack"):
_statemachine.transitionto("Move/Punch", { attack = attack})
if event.isactionpressed("jet"):
_statemachine.transitionto("Move/Hover", { velocity = velocity, hoverimpulse = hover_impulse })
func physicsprocess(delta: float) -> void:
var inputdirection: = getinputdirection()
var move_direction: = input_direction
if move_direction.length() > 1.0:
move_direction = move_direction.normalized()
move_direction.y = 0.0
if move_direction:
player.look_at(player.global_transform.origin + move_direction, Vector3.UP)
velocity = calculate_velocity(velocity, move_direction, delta)
velocity = player.move_and_slide(velocity, Vector3.UP)
static func getinputdirection() -> Vector3:
return Vector3(
Input.getactionstrength("moveright") - Input.getactionstrength("moveleft"),
0,
Input.getactionstrength("moveback") - Input.getactionstrength("movefront")
)
func calculatevelocity(
velocitycurrent: Vector3,
movedirection: Vector3,
delta: float
) -> Vector3:
var velocitynew := movedirection * movespeed
if velocitynew.length() > maxspeed:
velocitynew = velocitynew.normalized() * maxspeed
velocitynew.y = velocity_current.y + gravity * delta
return velocity_new
And here is the hover script:
extends PlayerState
func physicsprocess(delta: float) -> void:
_parent.physicsprocess(delta)
if player.is_on_floor():
_state_machine.transition_to("Move/Idle")
func enter(msg: Dictionary = {}) -> void:
match msg:
{"velocity": var v, "hoverimpulse": var hi}:
_parent.velocity = v + Vector3(0.0, hi, 0.0)
#skin.transitionto(skin.States.Hover)
_parent.enter(msg)
func exit() -> void:
_parent.exit()