+2 votes

Hi,
I have a script for flying object but I need to move up and down smoothly - slow/stop move? if it is possible for KinematicBody or need RigidBody?
Thanks for help

enter image description here

 extends KinematicBody

var t 
var r

export var FSpeed = 2
export var MSpeed = 2
export var RSpeed = 2

func _process(dt):
    t = get_transform()
    r = get_rotation()

    if(Input.is_action_pressed("ui_up")):
        t.origin += t.basis[2] * MSpeed * dt

    if(Input.is_action_pressed("ui_down")):
        t.origin += t.basis[2] * -MSpeed * dt

    if(Input.is_action_pressed("ui_right")):
        r += Vector3(0,-0.4,0) * RSpeed * dt

    elif(Input.is_action_pressed("ui_left")):
        r += Vector3(0,0.4,0) * RSpeed * dt

    if(Input.is_action_pressed("fly_up")):
        t.origin += t.basis[1] * FSpeed * dt

    if(Input.is_action_pressed("fly_down")):
        t.origin -= t.basis[1] * FSpeed  * dt





    set_transform(t)
    set_rotation(r)


func _ready():
    set_process(true) 

Note:
uiup is forward movement
ui
down is backward movement

in Engine by (450 points)
edited by

As I read the answer here somewhere, so you cannot use apply impulse for KinematicBody, which would be a solution for smooth motion (slow-stop) - impulse only for RigidBody.
Only for KinematicBody play somehow with gravity?...or am I completely off?
So the solution- RigidBody and apply the impulse(for RigidBody only)

THIS is flying script for like a hovercraft where is set apply impulse to the RigidBody ("hovercraft") but the problem here is that when cornering to the left-right does not fly forward...I mean left-forward and right-forward.
(Sorry for my bad English)

    extends Spatial

var h = ("hovercraft")



func _ready():
    h = get_node("hovercraft")
    self.set_process(true)


#Controls
func _process(delta):
    if Input.is_action_pressed("move_up"):
        h.apply_impulse(Vector3(0, 0, 0), Vector3(0, 0.5, 0))
    if Input.is_action_pressed("move_down"):
        h.apply_impulse(Vector3(0, 0, 0), Vector3(0, -0.5, 0))
    if Input.is_action_pressed("rotate_right"):
        h.set_angular_velocity(Vector3(0,-1,0)*deg2rad(25));
    if Input.is_action_pressed("rotate_left"):
        h.set_angular_velocity(Vector3(0,1,0)*deg2rad(25));
    if Input.is_action_pressed("forward"):
        h.apply_impulse(Vector3(0, 0, 0), Vector3(0, 0, -0.2))
    if Input.is_action_pressed("brake"):
        h.apply_impulse(Vector3(0, 0, 0), Vector3(0, 0, 0.2))

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.