Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


I’m utilizing Godot 3.4 with a inflexible physique for the participant character, I added a number of factor this character can do, like leap and leap larger with the assistance of a trampoline.

Now, I do know that inflexible physique has its personal gravity, nevertheless it felt floaty, so I added a bit extra of drive so the character can really feel a bit extra heavy.

My downside is that when the character walks over the trampoline, the primary leap is way larger than the following ones. This does not occur if the character jumps over the trampoline.

Code for the character’s leaping:

var jump_speed := 700.0
var gravity := 1.0
var gravity_speed := 0.0

var is_grounded := true

func _process(delta):
    if Input.is_action_just_pressed("ui_up") and is_grounded:
        _reset_gravity()
        apply_central_impulse(Vector2.UP *jump_speed)
    
    elif not is_grounded:
        gravity_speed += gravity + delta
        apply_central_impulse(Vector2.DOWN*gravity_speed)

func _integrate_forces(state):
    is_grounded = state.get_contact_count() > 0 and int(state.get_contact_collider_position(0).y) >= int(global_position.y)
    if is_grounded:
        _reset_gravity()

func _reset_gravity():
    gravity_speed = gravity_speed_default

The code for the trampoline:

extends StaticBody2D

var jumpoline_force := 3.0
const jump_spring := 1000
onready var sprite := $AnimatedSprite as AnimatedSprite
onready var boing := $BoingSound
var jump_direction := Vector2()

func _ready():
    jump_direction = Vector2(sin(rotation_degrees) ,-cos(rotation_degrees))


func _on_JumpArea_body_entered(physique):
     sprite.play("Spring") 
     boing.play()
     physique.apply_central_impulse(jump_direction * jumpoline_force * jump_spring)

Screenshot of 2D platformer with character jumping on trampoline

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments