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)