I am trying to create a characterBody3D that the player moves around, and I would like it to be able to rotate around a cylinder like in F-zero-X. Someone already solved this issue when using a rigidbody, where you can apply relative forces, helping to rotate the player:
Move Inside Pipe Like F-Zero GX
and I would like to replicate this using a characterBody3D and calculating its rotation instead of using forces. So I followed the recommendations from the previous post and added 3 raycasts around my characterBody.
The difference is that, since I am using a characterBody instead of a rigidbody, I can’t rotate it using forces…So I calculate the average normal across the collisions of the 3 raycasts weighed by the distance to the collision point:
var distanceA = Raycast1.get_collision_point().distance_to(Raycast1.global_position)
var distanceB = Raycast2.get_collision_point().distance_to(Raycast2.global_position)
var distanceC = Raycast3.get_collision_point().distance_to(Raycast3.global_position)
var TargetNormal= (1/distanceA * Raycast1.get_collision_normal() + 1/distanceB *Raycast2.get_collision_normal() + 1/distanceC * Raycast3.get_collision_normal()).normalized()
The problem is that I don’t know where to go from here. If I compare my characterBody’s basis.y to the TargetNormal, I should know how much to rotate my characterBody every tick, right? However, I’m not sure how to do that or if that would solve the problem. Help, please?