Trying to make the player bounce left.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By imnotfez


I am trying to make my player bounce to the right side on a “jumppad” and i have already set it up on the Y axis using

func _on_BounceArea_body_entered(body):
velocity.y = -spring_power

I am also trying to do this on the X axis but i cannot get it to work while using the same code, just rewritten for the X axis.

Here’s the code

extends KinematicBody2D

class_name Player

const UP = Vector2(0,-1)

export var gravity = 20 export var speed = 150 export var jump_power =
300 export var spring_power = 500 export var springp_hori = 500

var velocity = Vector2()

var jump_max = 2 var jump_count = 0

func _physics_process(delta): velocity.y += gravity if
Input.is_action_pressed(“move_right”): velocity.x = speed elif
Input.is_action_pressed(“move_left”): velocity.x =- speed else:
velocity.x = 0 if is_on_floor() and jump_count!=0: jump_count =
0 if jump_count<jump_max: if
Input.is_action_just_pressed(“jump”): velocity.y = -jump_power
jump_count += 1 velocity = move_and_slide(velocity, UP) func
_process(delta: float) → void: change_animation()

func change_animation(): if velocity.x > 0: $AnimatedSprite.flip_h
= false elif velocity.x < 0: $AnimatedSprite.flip_h = true if velocity.y < 0: $“jump”) else: if velocity.x
!= 0: $“walk”) else:

func _on_Fallzone_body_entered(body):

func _on_BounceArea_body_entered(body): velocity.y = -spring_power

func _on_HorizontalBounceArea_body_entered(body): velocity.x =

Let me know

:bust_in_silhouette: Reply From: Hexadotz

Are you trying to make a jump pad as if a trampoline that will lunch you in the air if you step on it?
If so you should give it it’s own scene and script then write something like this

func _on_jumppad_body_entered(body):
     If body.is_in_group("player"):
          Body.Velocity.y += bounce_height

However if you’re trying to make it so the player is like a spring you will need to check which direction the player is going to something like this:

func bouncer():
     If input.is_action_pressed("move_right") and Input.is_action_just_pressed("jump"):
          Velocity.y = jump_height
          Velocity.x += bounce_push

This is what i can provide because i don’t really understand what’s exactly you’re trying to achieve, hopefully this will help you