0 votes
ar gravity = 9.8

var location = Vector3()
var capncrunch = Vector3()
export var speed = 7
export var jump_height = 9
var velocity = Vector3()

func getinput():
velocity = Vector3()
if Input.is
actionpressed('uiright'):
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.is
actionpressed("uiforward"):
velocity.z -= 1
if Input.isactionpressed("ui_backwards"):
velocity.z += 1
velocity = velocity.normalized() * speed

func physicsprocess(delta):
getinput()
velocity = move
andslide(velocity)
move
andslide(globaltransform.basis.xform(capncrunch), Vector3.UP)

if Input.is_action_just_pressed("jump"):
    if is_on_floor():
        capncrunch.y = jump_height

if not is_on_floor():
    capncrunch.y -= gravity * delta
in Engine by (58 points)

Means do you want to make a fps type game in Godot?
Then you can search for Garbaj fps series. It will teach you
how to make a fps in Godot.

2 Answers

0 votes

Change all velocity.x, velocity.z to velocity.basis.x, velocity.basis.z

by (50 points)
0 votes

Each object has both a local and global transform (transform and global_transform, respectively). Which one you use depends on various circumstances, but the transforms are what you need. Assuming you are executing a script from within the object class itself, you can get the local direction vector with:

transform.basis.z

and the global direction vector with:

global_transform.basis.z

Then you can use move_and_collide or move_and_slide with this vector.

by (214 points)
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.