Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | imnotfez |
Hello,
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 = 500var 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: $AnimatedSprite.play(“jump”) else: if velocity.x
!= 0: $AnimatedSprite.play(“walk”) else:
$AnimatedSprite.play(“idle”)func _on_Fallzone_body_entered(body):
get_tree().change_scene(“res://World.tscn”)func _on_BounceArea_body_entered(body): velocity.y = -spring_power
func _on_HorizontalBounceArea_body_entered(body): velocity.x =
spring_power
Let me know