Godot Version
4.2.2
Question
I’m currently working on a 2d game which uses changing gravity as the only way of moving.
I’ve ran into an issue where the character has unwanted friction near walls which causes it to slow down instead of go straight in one direction.
The walls are made using tilemaps.
I also want the player to keep some of his momentum when changing gravity.
Here’s a video showcasing the issue (spikes aren’t solid yet)(sorry for bad quality):
https://youtu.be/IMgfhVZvSPE
And here’s the code:
extends CharacterBody2D
const GRAVITY = 500
var GravDir = 0 #Down
func _input(event):
if event.is_action_pressed("Down"):
GravDir = 0
%GravfallPlayerSprite.flip_v = false
%GravfallPlayerSprite.flip_h = false
%GravfallPlayerSprite.rotation_degrees = 0
%GravFallPlayerCol.rotation_degrees = 0
elif event.is_action_pressed("Up"):
GravDir = 1
%GravfallPlayerSprite.flip_v = true
%GravfallPlayerSprite.flip_h = true
%GravfallPlayerSprite.rotation_degrees = 0
%GravFallPlayerCol.rotation_degrees = 0
elif event.is_action_pressed("Left"):
GravDir = 2
%GravfallPlayerSprite.rotation_degrees = -90
%GravFallPlayerCol.rotation_degrees = -90
%GravfallPlayerSprite.flip_v = true
elif event.is_action_pressed("Right"):
GravDir = 3
%GravfallPlayerSprite.rotation_degrees = 90
%GravFallPlayerCol.rotation_degrees = 90
%GravfallPlayerSprite.flip_v = true
func _physics_process(delta):
if GravDir == 0: #Down
velocity.y += delta * GRAVITY
var motion = velocity * delta
move_and_collide(motion)
if GravDir == 1: #Up
velocity.y -= delta * GRAVITY
var motion = velocity * delta
move_and_collide(motion)
if GravDir == 2: #Left
velocity.x -= delta * GRAVITY
var motion = velocity * delta
move_and_collide(motion)
if GravDir == 3: #Right
velocity.x += delta * GRAVITY
var motion = velocity * delta
move_and_collide(motion)
Every attempt to help is greatly appreciated :D.