Why will the rotation mess up

Godot Version

4.6

Question

Why when I rotate it breaks like this

extends CharacterBody3D

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.

func align_with_y(xform, new_y):
	xform.basis.y = new_y
	xform.basis.x = -xform.basis.z.cross(new_y)
	xform.basis = xform.basis.orthonormalized()
	return xform

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if(!$RayCast3D.is_colliding()):
		velocity.y -= 5 * delta
	else:
		var input = Vector3(Input.get_axis("ui_left","ui_right"),0,Input.get_axis("ui_down","ui_up")).normalized() * global_basis
		var n = $RayCast3D.get_collision_normal()
		velocity = input * 10
		up_direction = n
		var xform = align_with_y(global_transform, n)
		global_transform = global_transform.interpolate_with(xform, 12 * delta)
	move_and_slide()

According to your code it aligns itself with the normal of the collider that was hit by the raycast, not with the input direction.

Ok, what is that supposed to mean

It’s a verbal explanation of what your code seems to be doing. Why is it doing that? I don’t know. You wrote it.

What is raycasting supposed to achieve here?

its supposed to do that so when you run up a wall or try to do a loop de loop you run up it, thats what I am trying to achieve sonic physics

I see. You’re mapping x,y input to x, z axes. Is your character moving in xy plane or in xz plane?

x and z for left and right and up and down when on flat ground

Can you post a video that shows the problem?

sure I can

It appears to be properly moving left and right. Which key triggers the “jump”?

thats the thing there is none, i havent made a jump yet, thats strange right

Yeah but what do you press when it happens?

I pressed right then the player gets stuck then I press left and then “jump”

I’d suggest starting with something simpler than sonic.

1 Like

figured it out I think