Godot Version
4.3.stable
Question
when ever I want to reach north pole it stops moving to that direction
I do not know what am I missing.
I even moved out
MovingVelocity = (body.global_basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() * SPEED
from if on floor just to be sure it should work
class_name ServerPlayer extends CharacterBody3D
#region interfaces
## enum of entity
var entity_num: int
var entity_string: String
#endregion
#region inputs
@onready var body = $body
@onready var cameraPivot = $body/Node3D
var camera: Node3D
const SPEED = 150.0
const JUMP_VELOCITY = 45
const sensitivity = 0.008
var gravity = 0.98
var gravityDirection
var gravityVelocity = Vector3.ZERO
var MovingVelocity = Vector3.ZERO
var initialized = false
@onready var animation_player: AnimationPlayer = $CollisionShape3D/RigidBody3D/visuals/mixamo_base/AnimationPlayer
#endregion inputs
#region start
func _ready():
camera = g_man.camera
camera.reparent(cameraPivot)
camera.position = cameraPivot.position
camera.rotation = cameraPivot.rotation
initialized = true
print("WARNING double rotation rotating to avoid gliches in _process(delta)")
#endregion start
#region event handling
func _input(event: InputEvent) -> void:
if not initialized:
return
if event is InputEventMouseMotion:
body.rotate_y(-event.relative.x * sensitivity)
camera.rotate_x(-event.relative.y * sensitivity)
#endregion end event handling
#region process
func _process(delta):
var onFloor = is_on_floor() or is_on_wall() or is_on_ceiling()
gravityDirection = g_man.planetPosition - position
gravityDirection.normalized()
#don't know why if I don't have 2 of these than I get glichy in the beginning. -> it doesn't turn my body around as it should for quite some time
rotation = (Quaternion(-transform.basis.y, gravityDirection) * transform.basis.get_rotation_quaternion()).normalized().get_euler()
#rotation = (Quaternion(-transform.basis.y, gravityDirection) * transform.basis.get_rotation_quaternion()).normalized().get_euler()
# Add the gravity.
if not onFloor:
gravityVelocity += gravityDirection * gravity
else:
gravityVelocity = Vector3.ZERO
# Get the input direction and handle the movement/deceleration.
var input_dir = Input.get_vector("left", "right", "forward", "back")
if(onFloor):
gravityVelocity = Vector3.ZERO
MovingVelocity = (body.global_basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() * SPEED
# Handle jump.
if Input.is_action_just_pressed("jump") and onFloor:
MovingVelocity -= gravityDirection * JUMP_VELOCITY
if onFloor and not MovingVelocity:
#velocity.x = move_toward(velocity.x, 0, SPEED * delta)
#velocity.z = move_toward(velocity.z, 0, SPEED * delta)
#velocity.y = move_toward(velocity.y, 0, SPEED * delta)
velocity = Vector3.ZERO
animation_player.play("idle")
else:
velocity = (gravityVelocity + MovingVelocity) * delta
animation_player.play("walking")
move_and_slide()
#endregion process