+1 vote

Hello Everyone
I currently have a player that is using the Kinematic Body for 3D. I'm currently working on a slide system and I want to add force in the direction of they key pressed. I also want to change the scale of the entire player(player is a capsule) to half the size and back to full size once crouch button is released. I have the basics down, I want to know I can use
state.AddForce(forcevector, Vector3(0,0,0)
to add force to the KinematicBody

extends KinematicBody

# Global Variables
export var MouseSensitivity = 0.05

export var MovementSpeed = 7
export var Acceleration = 20
export var GravityForce = 9.8

export var CounterMovement = 0.175
export var MaxSlopeAngle = 35

export var JumpForce = 5.5
export var SlideForce = 4
export var SlideCounterMovement = 0.2
export var CanSlideValue = 5

# Local Variables
var Threshold = 0.01
var Direction = Vector3()
var Velocity = Vector3()
var Fall = Vector3()
var CrouchScale = Vector3(1, 0.5, 1)
var PlayerScale = Vector3()

onready var head = $Head

# Functions
func _ready():
    PlayerScale = get_scale()

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

func _process(delta):

    # Mouse Visblity
    if Input.is_action_just_pressed("ui_cancel"):

    # Movement Input
    Direction = Vector3()
    if Input.is_action_pressed("MoveForward"):
        Direction -= transform.basis.z
    elif Input.is_action_pressed("MoveBackward"):
        Direction += transform.basis.z
    if Input.is_action_pressed("MoveRight"):
        Direction += transform.basis.x
    elif Input.is_action_pressed("MoveLeft"):
        Direction -= transform.basis.x
    # Calculate Velocity & Direction
    Direction = Direction.normalized()
    Velocity = Velocity.linear_interpolate(Direction * MovementSpeed, Acceleration * delta)
    Velocity = move_and_slide(Velocity, Vector3.UP)
    move_and_slide(Fall, Vector3.UP)

    # Jump Input
    if not is_on_floor():
        Fall.y -= GravityForce * delta
    if Input.is_action_just_pressed("Jump"):
        Fall.y = JumpForce
    # Crocuh Input
    if Input.is_action_pressed("Crouch"):
    elif Input.is_action_just_released("Crouch"):

func startcrouch():
    PlayerScale = set_scale()
    if Velocity >= CanSlideValue:
        state.addforce(SlideForce, Vector3())
func stopcrouch():
in Engine by (15 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 Frequently asked questions and 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 [email protected] with your username.