Character stops when going up a hill

Godot Version

4

Question

I am making a 2d platforming game based off the Google Dino Game when you lose internet and when I try to go up a hill it just stops the character, i’m using move and slide and the hill is less then the max angle and i’m confused why it wont go up. It might be because the character and collision box is a square but i’m not sure.

Code:

extends CharacterBody2D



var playerX = 0
var playerY = 0

const SPEED = 300.0
var JUMP_VELOCITY = -400.0
const pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
var slidingSpeed = 2000
var coyote_time 
var jumping = false
var coyoteStrength = 0.3   #SECONDS
var safe = 1 
var score = 0
var highScore = 0




func _ready():
	coyote_time = Timer.new()
	coyote_time.one_shot = true
	coyote_time.autostart = false
	coyote_time.wait_time = coyoteStrength
	add_child(coyote_time)
	
   
func _physics_process(delta: float) -> void:
	# Add the gravity.
	if (!is_on_floor()):
		velocity += get_gravity() * delta


func _process(_delta: float) -> void:
	Character.playerX = position.x
	Character.playerY = position.y
	Character.score = Character.score + 1


	if is_on_floor():
		rotation = get_floor_angle()
		jumping = false
		safe = 1
		slidingSpeed = slidingSpeed + 0.1
		velocity.x = slidingSpeed
	# Handle jump.
	if Input.is_action_just_pressed("ui_accept"):
		if (is_on_floor() || !coyote_time.is_stopped()):
			velocity.y = JUMP_VELOCITY
			jumping = true
			safe = 0
			coyote_time.stop()



	if (!is_on_floor() && jumping == false && safe == 1):
		coyote_time.start()
		safe = 0


	move_and_slide()

(Don’t worry about some of the weird variables I have)

Can you show a screenshot of your scene in the editor so that it shows the CollisionShapes of the floor and the player? I think you’re just getting stuck on the collision shape.

PS: I just want to say that I love the fact that you declared your const pi with 100 decimal places even though:

  1. Godot already has a PI constant you can use,
  2. Godot can handle floats up to 14 decimal places only, so the other 86 will be wasted,
  3. NASA used only 15 decimal places when they sent a man on the moon, rookies. :slight_smile:
3 Likes

I knew 1 and 3 (PI just wasn’t working for me for some reason) but i didn’t know 2 so thanks for the info.

Here is a screenshot of the slope scene


(Sorry it took awhile I haden’t had internet for like 3 hours

I tried recreating your setup and I don’t see any issue, you can see here:

The only change I did was I reversed the floor angle, try doing the same in your project. I don’t think this will fix your problem, but worth a shot.

	rotation = -get_floor_angle()
1 Like

I can’t try it right now but I will I can but something worth adding that I’m using “procedural generation” or something along those lines

It did not seem to fix the problem and its confusing because it also stops all of my movements even though its continuously updating to a number that is only going up and not lowering. Maybe that could be part of the problem but I doubt its much.

It also seems that landing on the hill does not even change the rotation to the hill if i land directly on top of the slope?!!?!!? Maybe i should try using a rayast but I dont know why my way does not work

Welp I got it to work I just moved the slope part of the slope scene and it just fixed itself?