Godot Version
4
Question
Hey, i am making a platformer where i can use a shotgun for jumping but the movement from the shotgun jump is too jumpy. can you help me?
extends CharacterBody2D
@onready var node = $Node2d/Player
const SPEED = 300.0
const JUMP_VELOCITY = -500.0
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
if Input.is_action_just_pressed("shoot"):
var mousepointer = get_global_mouse_position()
global_position = global_position.move_toward(mousepointer, SPEED)