(Edit Begin)
Godot 3.0 Stable
Linux Ubuntu 18.10
Player scene consists of kinematic body with child sphere collision around body(mentioned later)
Child Spacial "Head" Mesh and collision Sphere + camera node
Child Spacial "Body" Mesh and collision Capsule
Child Spacial "Left Arm" Mesh and Collision Sphere
Child Spacial "Right Arm" Mesh and Collision Sphere
Child Spacial "Left Leg" Mesh and Collision Capsule
Child Spacial "Right Leg" Mesh and Collision Capsule
Main scene consists of a (200, 0.5, 200) Mesh Square with Collision as Main Floor
And various other objects created as meshes with collisions as a basic test map.
Root Tree Kinematic Body is the only one with a Script (Script Below)
(Edit End)
Problem:
I attempted to make a basic FPS with camera and player position facing mouse position, however when I run the main scene my character goes balistic and gravity pulls it up left then down right and multiple ways even if I don't move the mouse position or hit any buttons. I also noticed that the camera ignores my instructions not to go past >90 and <-90. Does anybody know where I went wrong or have any suggestions? Here is my Player Script below.
extends KinematicBody
var camera_angle = 0
var mouse_sensitivity = 0.3
var velocity = Vector3(0, 0, 0)
var direction = Vector3(0, 0, 0)
var gravity = -9.8
const MAX_SPEED = 20
const MAX_RUNNING_SPEED = 30
const ACCEL = 2
const DEACCEL = 6
var jump_height = 15
func _ready():
pass
func _physics_process(delta):
direction = Vector3()
var aim = $Head.get_global_transform().basis
if Input.is_action_pressed("ui_up"):
direction -= aim.z
if Input.is_action_pressed("ui_down"):
direction += aim.z
if Input.is_action_pressed("ui_left"):
direction -= aim.x
if Input.is_action_pressed("ui_right"):
direction += aim.x
direction = direction.normalized()
velocity.y += gravity * delta
var temp_velocity = velocity
temp_velocity.y = 0
var speed
if Input.is_action_pressed("move_sprint"):
speed = MAX_RUNNING_SPEED
else:
speed = MAX_SPEED
var target = direction * speed
var acceleration
if direction.dot(temp_velocity) > 0:
acceleration = ACCEL
else:
acceleration = DEACCEL
velocity = velocity.linear_interpolate(target, acceleration * delta)
velocity.x = temp_velocity.x
velocity.z = temp_velocity.z
velocity = move_and_slide(velocity, Vector3(0, 1, 0))
func _input(event):
if event is InputEventMouseMotion:
$Head.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
var change = event.relative.y * mouse_sensitivity
if change + camera_angle <90 and change + camera_angle > -90:
$Head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))