So I am wanting my character to change gravity but I am not sure how to proceed. I took a normal FPS template (And edited it a lot) and in order to preserve as much of the code as possible I changed all instances of velocity to a variable called base_velocity and at the end of _physics_process(delta) I set velocity equal to base_velocity right before move_and_slide().
How would I change the gravity_axis variable to, an upward vector that is the angle of an area the player would enter (and the area would give the angle to the player). Right now for full motion gravity_axis = Vector3(1, 1, 1)
How would I change the velocities for movement? I’ve already figured how to rotate the character (x and z) compared with the gravity vector so would I use that?
When you make an FPS, you use a combination of the direction of the character and a set speed to give it horizontal movement or “walking” using velocity.x and velocity.z, but with these two you have to calculate what speed they would be in the direction the character is facing. E.g, forward is (x=0, z=1), to the right would be (x=1,z=0) and forward/right would be (x=sqrt(2), x=sqrt(2)) as the velocity vector doesn’t rotate with the object. Then y you know is always jumping and gravity and only ever has two directions: up and down. But all of this is just for one possible gravity.
Because the velocities don’t rotate with the character, I have to account for y being a “walking” axis and say x being for jumping. Gravity is already taken care of, but the character’s movement needs to be rotated somehow.
When the character walks into one of the gravity areas, one at an angle of 45, and then jump, they don’t jump perpendicularly from the surface as they are supposed, and their x and z velocities are fighting against the slope.
You can get local “rotated” 3D Vectors by multiplying them by the global_basis.
extends CharacterBody3D
func _physics_process(delta: float) -> void:
var local_up_vector: Vector3 = global_basis * Vector3.UP
# then use this vector in your calculations for jumping
var local_forward_vector: Vector3 = global_basis * Vector3.FORWARD
# then use this vector in your calculations for walking
# etc.