0 votes

I was trying to implement "rocket jumping" and i encountered a problem. While it works fine when player is already in the air, if character is standing on the ground, it only slide short distance. Problem is only encounteded when character entered area of blast, if same code called by character itself it still works.

Here's the code for player controller and blast area

player controller:

extends KinematicBody

export var accel = {"ground" : 7, "air" : 2, "blast" : 10}
export var jumpForce = 10
export var moveSpeed = 10
export var mouse_sens = .1

onready var gravity = 19.6
onready var head = $Head
onready var camera = $Head/Camera
onready var ray = $Head/Ray

var gravity_vector = Vector3()
var direction = Vector3()
var velocity = Vector3()
var movement = Vector3()
var snap
var activeAccel

var isJumped = false

var blastZone = preload("res://Blast.tscn")

func _ready():

    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):

    if event is InputEventMouseMotion:
        rotate_y(deg2rad(-event.relative.x * mouse_sens))
        head.rotate_x(deg2rad(-event.relative.y * mouse_sens))
        head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))

func _process(delta):

    direction = Vector3.ZERO
    var horizontalRotation = global_transform.basis.get_euler().y
    var forwardInput = Input.get_action_strength("backward") - Input.get_action_strength("forward")
    var strafeInput = Input.get_action_strength("right") - Input.get_action_strength("left")
    direction = Vector3(strafeInput, 0, forwardInput).rotated(Vector3.UP, horizontalRotation).normalized()

    if Input.is_action_just_pressed("jump") && is_on_floor():
        isJumped = true

    if Input.is_action_just_pressed("shoot"):
        if ray.is_colliding():
            var spawnedZone = blastZone.instance()
            add_child(spawnedZone)
            spawnedZone.global_transform.origin = ray.get_collision_point()
            spawnedZone.set_as_toplevel(true)

    camera.set_as_toplevel(true)
    camera.global_transform.origin = camera.global_transform.origin.linear_interpolate(head.global_transform.origin, 40 * delta)
    camera.rotation.y = rotation.y
    camera.rotation.x = head.rotation.x

func _physics_process(delta):
    if is_on_floor():
        snap = -get_floor_normal()
        activeAccel = accel["ground"]
        gravity_vector = Vector3.ZERO
    else:
        snap = Vector3.DOWN
        activeAccel = accel["air"]
        gravity = 19.6
        gravity_vector += Vector3.DOWN * gravity * delta

    if isJumped && is_on_floor():
        snap = Vector3.ZERO
        gravity_vector = Vector3.UP * jumpForce
        isJumped = false

    velocity = velocity.linear_interpolate(direction * moveSpeed, activeAccel * delta)
    movement = velocity + gravity_vector

    var move = move_and_slide_with_snap(movement, snap, Vector3.UP)

func blast(blastVector, blastForce):
    snap = Vector3.ZERO
    activeAccel = accel["blast"]
    if is_on_floor():
        velocity = velocity + (blastVector * (blastForce * 3))
        gravity_vector = Vector3.ZERO
    else:
        gravity_vector = (gravity_vector / 2) + (blastVector * blastForce)

Blast area:

extends Area

onready var blastForce = 10

func _on_body_entered(body):
    if body.is_in_group("player"):
        var blastVector = (body.global_transform.origin - self.global_transform.origin).normalized()
        blastVector += Vector3.UP
        body.blast(blastVector, blastForce)

func _on_timeout():
    queue_free()

I tried setting snap value to 0, but character still slide and don't stop untill they jump.

Here is how it looks

Godot version 3.3.2 stable official
in Engine by (12 points)

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.