GDScript... please help me create a movement script I follow every guide and nothing is working!!!


Ad

Advertisements

Joined
Jun 25, 2019
Messages
2
Reaction score
0
extends KinematicBody
var gravity = -9.8
var velocity = Vector3()
var camera = get_global_transform("/...camera")
const SPEED = 6
const ACCELERATION = 3
const DE_ACCELERATION = 5
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass
func _physics_process(delta):
var dir = Vector3()
if(Input.is_action_pressed("move_fw")):
dir += -camera.basis[2]
if(Input.is_action_pressed("move_bw")):
dir += camera.basis[2]
if(Input.is_action_pressed("move_l")):
dir += -camera.basis[0]
if(Input.is_action_pressed("move_r")):
dir += camera.basis[0]

dir.y = 0
dir = dir.normalized()

velocity.y += delta * gravity

var hv = velocity
hv.y = 0

var new_pos = dir * SPEED
var accel = DE_ACCELERATION

if (dir.dot(hv) > 0):
accel = ACCELERATION

hv = hv.linear_interpolate(new_pos, accel * delta)

velocity.x = hv.x
velocity.z = hv.z

velocity = move_and_slide(velocity, Vector3(0,1,0))
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top