Godot Version
4.4
Question
So I’m making a character controller in Godot, using my own gravity system, and whenever it lands on a surface, it kind of goes in it a little, depending on the speed of how fast it’s falling. I’ve tried what I can, so decided to come here for advice.
It’s an animated sprite with 3 hitboxes in it, one left, one bottom, and one right for colliding with the floors and walls.
I’ve checked, and no, the collision shapes are not a scale different than 1, 1. So that can’t be the issue.
Here’s the code:
extends AnimatedSprite2D
var currentGravity = 0;
var gravityForce = 10;
var speed = 200;
var collidingBottom = false;
var collidingLeft = false;
var collidingRight = false;
var jumping = false;
func _process(delta: float) -> void:
if !collidingBottom || jumping:
currentGravity += gravityForce*delta;
self.position.y += currentGravity;
if Input.is_action_pressed("Left") && !collidingLeft:
self.position.x -= speed*delta;
if Input.is_action_pressed("Right") && !collidingRight:
self.position.x += speed*delta;
if Input.is_action_just_pressed("Jump") && collidingBottom:
jumping = true;
currentGravity = -3;
func _on_collisions_area_entered(area: Area2D) -> void:
if area.name == "Bottom Hitbox":
collidingBottom = true
jumping = false;
currentGravity = 0;
if area.name == "Right Hitbox":
collidingRight = true;
if area.name == "Left Hitbox":
collidingLeft = true;
func _on_collisions_area_exited(area: Area2D) -> void:
if area.name == "Bottom Hitbox":
collidingBottom = false;
if area.name == "Right Hitbox":
collidingRight = false;
if area.name == "Left Hitbox":
collidingLeft = false;