Saturday, October 1, 2022
HomeGame Developmentsecond - Godot 3.4 Downside with gravity and and rigidbody

second – Godot 3.4 Downside with gravity and and rigidbody


I’ve this drawback, i am utilizing a inflexible physique for the participant character, i added a couple of factor this character can do, like soar and soar greater with assist of trampoline.

Now, i do know that inflexible physique has it is personal gravity however it felt floaty, so i added a bit extra of drive so the character can really feel like a bit extra heavy.

My drawback is that when the character walks over the trampoline, the primary soar is approach greater than the subsequent ones, this does not occurs if the character jumps over the trampoline.

Code for leaping for the character:

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

var is_grounded := true

func _process(delta):
    if Enter.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)

Image

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments