0 votes

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 move
speed: = 25.0
export var gravity: = -80.0
export var jumpimpulse: = 25.0
export var attack: = 10.0
export var hover
impulse: = 10.0
var velocity: = Vector3.ZERO

func unhandledinput(event: InputEvent) -> void:
if event.is
actionpressed("jump"):
_state
machine.transitionto("Move/Air", { velocity = velocity, jumpimpulse = jumpimpulse })
elif event.is
actionpressed("attack"):
_state
machine.transitionto("Move/Punch", { attack = attack})
if event.is
actionpressed("jet"):
_state
machine.transitionto("Move/Hover", { velocity = velocity, hoverimpulse = hover_impulse })

func physicsprocess(delta: float) -> void:
var input
direction: = 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(
velocity
current: Vector3,
movedirection: Vector3,
delta: float
) -> Vector3:
var velocity
new := movedirection * movespeed
if velocitynew.length() > maxspeed:
velocitynew = velocitynew.normalized() * maxspeed
velocity
new.y = velocity_current.y + gravity * delta

    return velocity_new

And here is the hover script:

extends PlayerState

func physicsprocess(delta: float) -> void:
_parent.physics
process(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.transition
to(skin.States.Hover)
_parent.enter(msg)

func exit() -> void:
_parent.exit()

Godot version 3.1
in Engine by (13 points)

Code is quite hard to read (formatting issue).

I noticed you are using a state machine. It looks like 3d Mannequiny by GDQuest.

I would start by making a copy of Jump state and then removing the gravity logic, I don't remember if that was in the base Move player state, you could always generate a new base state without inheriting from Move.

And you could split in two different states: one for the "jump" part where you reach the max elevation then after few seconds transition to the actual hover part where you don't fall.

Then you could transition to Jump/Fall state when you finish water or whatever form of energy you use for your jetpack.

Cool. Thanks for the advice.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.