# How can I make move_and_slide play nice with a gravity point?

### Godot Version

v4.1.1.stable.official [bd6af8e0e]

So I’m currently testing my sprite for a space platformer, I’ve got them responding to a central gravity point and snapping to the ground correctly…But I have a few problems to solve:

### Question

1.How can I make move_and_slide check its max_floor_angle against the up_direction?

2.Is there a good way to implement movement perpendicular to the up_direction?

3.Would this be the right way to go about making my sprite treat the round object like a flat surface?

I’m fairly new at this and any help would be much appreciated, I’ll attach my player script as well

Player Script

extends CharacterBody2D

var MaximumVelocity = 500

var GroundSpeed = 150
var GroundAcceleration = 500

var JumpVelocity = -50
var SmoothJumpVelocity = JumpVelocity * .25

var ThrustY = -6
var BoostX = 12

var RotDirection = rotation
var RotSpeed = 2

var GravityPull = Vector2(0 ,163)
var RotationOnFloor = 0

func _physics_process(delta):
var InputAxis = Input.get_axis(“ui_left”, “ui_right”)
handle_jump_and_fly(delta)
handle_acceleration(InputAxis, delta)
update_animations(InputAxis)
handle_gravity(delta)
move_and_slide()
push_items(delta)
print("Position is ", position)
print("Velocity is ", velocity)
print("GravityPull is ", GravityPull)
print("Up is ", up_direction)
print("Rotation is ", rotation)
print("Velocity is ", velocity)
print(transform.x)

func _on_area_2d_give_gravity_vector(WellPosition):
GravityPull = WellPosition - position
GravityPull = GravityPull.normalized() * 163
up_direction = GravityPull * -1

func _on_area_2d_body_exited(_body):
GravityPull = Vector2(0 ,163)
up_direction = Vector2( 0, -1)

func handle_gravity(delta):
velocity += GravityPull * delta

func push_items(_delta):
var PushForce = 80.0
for i in get_slide_collision_count():
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * PushForce)

func handle_acceleration(InputAxis, delta):
if is_on_floor() and InputAxis != 0:
velocity.x = move_toward(velocity.x, GroundSpeed * InputAxis, GroundAcceleration * delta)
#this is new-V
velocity = velocity + transform.x
elif is_on_floor():
velocity.x = move_toward(velocity.x , 0, GroundSpeed)
#this is new-V
velocity = velocity + transform.x

func handle_jump_and_fly(delta):
if is_on_floor():
var ReverseUp = up_direction * -1
rotation = ReverseUp.orthogonal().angle()
if Input.is_action_just_pressed(“ui_up”):
velocity = (velocity + transform.y * JumpVelocity)
elif Input.is_action_just_released(“ui_up”) and velocity.y < SmoothJumpVelocity:
velocity.y += SmoothJumpVelocity
if not is_on_floor():
RotDirection = Input.get_axis(“ui_left”, “ui_right”)
rotation += RotDirection * RotSpeed * delta
if Input.is_action_pressed(“ui_up”):
velocity = (velocity + transform.y * ThrustY)
if Input.is_action_pressed(“ui_down”):
if sprite_is_flipped() == true:
reverse_boost()
else:
boost()

func boost():
velocity = (velocity + transform.x * BoostX)

func reverse_boost():
velocity = (velocity - transform.x * BoostX)

func update_animations(InputAxis):
if is_on_floor():
if InputAxis > 0:
animated_sprite_2d.play(“run_right”)
animated_sprite_2d.flip_h = false
if InputAxis < 0:
animated_sprite_2d.play(“run_left”)
animated_sprite_2d.flip_h = true
if InputAxis == 0:
animated_sprite_2d.play(“idle”)
else:
if not is_on_floor():
animated_sprite_2d.play(“jump”)

func sprite_is_flipped():
if animated_sprite_2d.is_flipped_h():
return true
else:
return false