![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | bastilo |
Hi guys,
right now I’m starting to learn 3D. My first little project is a simple FPS control scheme. It works, but it is very shaky. Please tell me what I’m doing wrong. Here is my code:
extends RigidBody
const MOUSE_SPEED = 0.01
const WALK_SPEED = 0.2
func _input(event):
if event is InputEventMouseMotion:
_turn_head(event.relative * Vector2(-MOUSE_SPEED, MOUSE_SPEED))
func _physics_process(delta):
if Input.is_action_pressed("walk_forward"):
translate(Vector3(0, 0, WALK_SPEED))
if Input.is_action_pressed("walk_backward"):
translate(Vector3(0, 0, -WALK_SPEED))
if Input.is_action_pressed("strafe_left"):
translate(Vector3(WALK_SPEED, 0, 0))
if Input.is_action_pressed("strafe_right"):
translate(Vector3(-WALK_SPEED, 0, 0))
func _turn_head(turn_by):
rotate_y(turn_by.x)
$Camera.rotate_x(turn_by.y)
if $Camera.rotation_degrees.x > 90.0:
$Camera.rotation_degrees.x = 90.0
elif $Camera.rotation_degrees.x < -90.0:
$Camera.rotation_degrees.x = -90.0
You are using a RigidBody
for character control? I would use a KinematicBody
instead.
SIsilicon | 2018-12-23 15:38
I want to have the physics engine to handle gravity etc.
bastilo | 2018-12-23 15:44
It doesn’t take too much code to implement gravity. Besides. It’s much more flexible this way. This is for 2D, but the idea is pretty much the same.
SIsilicon | 2018-12-23 21:27