Home Game Development 2nd – Godot 3.4 Problem with gravity and and rigidbody

2nd – Godot 3.4 Problem with gravity and and rigidbody

0
2nd – Godot 3.4 Problem with gravity and and rigidbody

[ad_1]

I’ve this downside, i am utilizing a inflexible physique for the participant character, i added a number 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 power so the character can really feel like a bit extra heavy.

My downside is that when the character walks over the trampoline, the primary soar is means greater than the following 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 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)

Image

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here