Mi movimiento no termina de funcionar

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Raylandia7

Por alguna razón, llegado a cierto momento, el programa deja de detectar las colisiones con el suelo y, por lo cual, el personaje deja de saltar. Amas, Cuando intento subir una rampa, el personaje se vuelve loco y empieza a caminar solo en dirección contraria.

Aquí esta mi codigo:

extends KinematicBody

var Posicion = Vector3.ZERO
var SaltoDispon = true
export (int) var Gravedad
export (int) var salto
export var h_sensibilidad = 0.001
export var v_sensibilidad = 0.002
export var velocidad = 14

func _ready():

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):

if event is InputEventMouseMotion:
	
	rotate_y( - event.relative.x * h_sensibilidad )
	
	
	$Camera.rotate_x( - event.relative.y * v_sensibilidad )

func _process(delta):
var vel_actual = Vector3(0, 0, 0)

if Input.is_action_pressed("ui_up"):
	vel_actual.z -= velocidad
if Input.is_action_pressed("ui_down"):
	vel_actual.z += velocidad


if Input.is_action_pressed("ui_left"):
	vel_actual.x -= velocidad
if Input.is_action_pressed("ui_right"):
	vel_actual.x += velocidad

vel_actual = vel_actual.rotated( Vector3(0, 1, 0), rotation.y )

move_and_slide( vel_actual )

func _physics_process(delta):

Posicion.y -= Gravedad * delta

if is_on_floor():
	SaltoDispon = true
	print("tocado")
if Input.is_action_pressed("saltar") and SaltoDispon:
	Posicion.y = salto
	SaltoDispon = false

Posicion = move_and_slide(Posicion,Vector3(0, 1, 0))

For some reason, at a certain point, the program stops detecting collisions with the ground and therefore the character stops jumping. When I try to go up a ramp, the character goes crazy and starts walking alone in the opposite direction.

I feel that the script misses the return from move_and_slide in _process as noted here: Physics introduction — Godot Engine (3.5) documentation in English but also, there’s movement in both _process and _physics_process possibly conflicting with each other. Get the movement in _process, move the character in _physics_process.

It might be worth considered using move_and_collide too.

(more docs that may be helpful: Kinematic character (2D) — Godot Engine (3.5) documentation in English)

spaceyjase | 2023-06-27 10:09

Muchas gracias, pero sigue sin funcionar, aun así, agradezco el intento. :slight_smile:

Raylandia7 | 2023-06-27 20:09