#How to make a 3D controller that can walk on walls Rigidbody3D or CharacterBody3D works

6 messages · Page 1 of 1 (latest)

pastel current
#

Idk how I'm suppose to make a 3D controller that can walk on walls, and its kinda the enntire point of the game

pastel current
#

broken weird controller code

#

class_name player_movement
extends CharacterBody3D

@onready var _player : Object = $"."

@onready var _camera : Object = $Seperator/CameraSystem/RotationJoint01

@onready var _surface_ray : Object = $RayCast3D

var input_dir : Vector2
var direction : Vector3

var speed = WALK_SPEED
const WALK_SPEED = 5.0
const RUN_SPEED = 8.0
const CROUCH_SPEED = 2.0

const JUMP_VELOCITY = 5.8

const GRAVITY : float = 9.8

func _physics_process(delta) -> void:
if not is_on_floor():

_player.velocity = Vector3(0, -1, 0).rotated(Vector3.UP, rotation.y) * GRAVITY * delta

    _player.velocity.y -= GRAVITY


if Input.is_action_just_pressed("MOVE_JUMP") and is_on_floor():
    _player.velocity.y = JUMP_VELOCITY


direction = (-_camera.transform.basis.z * Vector3(input_dir.x, 0, input_dir.y)).normalized()

input_dir = Input.get_vector("MOVE_LEFT", "MOVE_RIGHT", "MOVE_UP", "MOVE_DOWN")

if is_on_floor() == true:
    if direction:
        _player.velocity.x = direction.x * speed
        _player.velocity.z = direction.z * speed
    else:
        _player.velocity.x = lerp(velocity.x, direction.x * speed, delta * 7.0)
        _player.velocity.z = lerp(velocity.z, direction.z * speed, delta * 7.0)
else:
    _player.velocity.x = lerp(_player.velocity.x, direction.x * speed, delta * 3.0)
    _player.velocity.z = lerp(_player.velocity.z, direction.z * speed, delta * 3.0)



if _surface_ray.is_colliding():
    _player.rotation.x = lerp(_player.rotation.x, _surface_ray.get_collision_normal().z, 0.25)
    _player.rotation.z = lerp(_player.rotation.z, -_surface_ray.get_collision_normal().x, 0.25)

move_and_slide()
waxen blade
#

working on it rn