+1 vote

I'm just a new Godot user (been a few months but probably totaled about a few weeks) and I had a 3D character. It works fine (jumping had problems but not my first priority for now,) until I jump while touching walls. As I do so I would instead fly up real quick instead of jump.

With a bit of diagnosing I saw that is-on-floor would register walls as floors(?), thus returning true apparently. This already bugs me and I don't know how to fix this. Please help me. Thanks in advance!

Code (sorry, kinda messy):

extends KinematicBody

###### EXPORT

export(NodePath) var CameraObject
export var StepCheckDistance = 1.2
export var StepCheckSensitivity = 0
export var StepCheckStrength = 0.4

###### CONSTANTS

enum ANIMATION_TAG { # no animations yet but ok
    Master_Idle_None,
    Minor_Idle_Knife,
    Minor_Idle_Shortsword,
    Minor_Idle_Longsword,
    Minor_Idle_Spear,
    Minor_Idle_Handgun,
    Minor_Idle_Bow,
    Minor_Idle_Longgun,

}

###### ONREADY

onready var StepChecker = get_node("step_check")
#onready var Collision = get_node("collision")
onready var Collision_Capsule = get_node("collision_capsule")
onready var Animate = get_node("animate")

###### SET

onready var Cam = get_node(CameraObject)

###### LIVE VARIABLES

# MOVEMENT

var movementStates = {
    "FRWD" : false,
    "BKWD" : false,
    "LFWD" : false,
    "RTWD" : false,
    "CRCH" : false,
}
var mS2 = {
    "SPNT" : false,
}

var jumping = false

var speed = 3
var runSpeed = 11
var xAcc = {acc = 4, deacc = 7}
var dir = Vector3(0, 0, 0)
var velocity = Vector3()
var v_mag = 0
var prevPos = Vector3()
var shiftorcrouch = 0
var accel = 0

###### LIVE DEBUG VARIABLES

# None

###### FUNCTIONS

func GetShortestAngle(start, end):
    return fmod(2 * fmod(start - end, PI * 2), PI * 2) - fmod(start - end, PI * 2)

func CheckForTrue(Table):
    for i in Table.values():
        if i == true:
            return true
    return false

func _ready():
    Collision_Capsule.shape.set("slips_on_slope", false)

func _physics_process(delta):
    # MOVEMENT SECTION
    var g_grav = ProjectSettings.get_setting("physics/3d/default_gravity")
    var y_Dir = GetShortestAngle(self.rotation.y, Cam.rotation.y)
    var mltplr = 1
    var motion = speed

    prevPos = translation

    if CheckForTrue(movementStates):
        var clamped = clamp(y_Dir, -3, 3)
        if clamped < 0:
            rotation.y -= (clamped / 6)
        elif clamped > 0:
            rotation.y += (-clamped / 6)    

    if mS2.SPNT == true:
        motion = runSpeed
    elif movementStates.CRCH == true:
        mltplr = 0.5

    velocity = Vector3(lerp(velocity.x, dir.x * motion * mltplr, accel), velocity.y, lerp(velocity.z, dir.z * motion * mltplr, accel))

# warning-ignore:return_value_discarded
    move_and_slide_with_snap(velocity, Vector3.DOWN * Vector3(.1, .1, .1), Vector3.UP, true, 4, 38)

    velocity.y -= g_grav * delta
    ################################### From here
    if !is_on_floor():
        accel = 0.07
        jumping = false
        print("On air")
    else:
        print("On floor")
        accel = 0.17
        if jumping:
            velocity.y += 12
    ###################################  To here
    v_mag = abs(velocity.x + velocity.y + velocity.z)



# warning-ignore:unused_argument
func _process(delta):
    ###################### MOVEMENT ######################
    dir = Vector3()
    for key in movementStates.keys():
        movementStates[key] = false
    for key in mS2.keys():
        mS2[key] = false

    if Input.is_action_pressed("player_forward"):
        dir += -global_transform.basis.z
        movementStates.FRWD = true
    if Input.is_action_pressed("player_backward"):
        dir += global_transform.basis.z
        movementStates.BKWD = true
    if Input.is_action_pressed("player_leftward"):
        dir += -global_transform.basis.x
        movementStates.LFWD = true
    if Input.is_action_pressed("player_rightward"):
        dir += global_transform.basis.x
        movementStates.RTWD = true

    if Input.is_action_pressed("player_sprint"):
        mS2.SPNT = true

    if Input.is_action_pressed("player_downward"):
        movementStates.CRCH = true

    if Input.is_action_pressed("player_upward"):
        jumping = true
        print("JUMP STATE")

    dir = dir.normalized()
    ################### FUNCTION CALLS ###################
in Engine by (13 points)

Is what you're using as floor the same as the wall?

I had this same issue, my mistake was that I was passing a higher value to floormaxangle in moveandslide. That was the reason that walls were treated as floor.
Passing a lower value fixed it

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.