0 votes

so yeah i want make a simple weapon switching system and i cant seem to figure it out please help me
my entire code:(do you mind looking at the whole code while u r at it cause i made most of it myself and dont know if its good)

extends KinematicBody2D

var speed = 250
var GRAVITY = 600.0
var velocity = Vector2()
var jumpforce = -350
var hand = false
var sword = false
var swordobtained = false
var bow
obtained = false

func _ready():
hand = true

func process(delta):
velocity.y += _delta * GRAVITY

if Input.is_action_pressed("left"):
    velocity.x = -speed
    if is_on_floor():
        if sword_obtained == false:
    $AnimatedSprite.flip_h = true
elif Input.is_action_pressed("right"):
    velocity.x =  speed
    if is_on_floor():
        if sword_obtained == false:
    $AnimatedSprite.flip_h = false
    velocity.x = 0
    if is_on_floor():
        if sword_obtained == false:
        elif sword_obtained == true:
        elif sword == true:

if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = jumpforce
    if sword_obtained == false:
if is_on_floor() == false:
    speed = 300
if is_on_floor():
    speed = 250
if Input.is_action_pressed("ui_down"):
    GRAVITY = 1200.0
elif Input.is_action_just_released("ui_down"):
    GRAVITY = 600.0

move_and_slide(velocity, Vector2(0, -1))

if Input.is_action_just_pressed("hand"):
    hand = true
    sword = false
if Input.is_action_just_pressed("sword") and sword_obtained == true:
    hand = false
    sword = true
    if Input.is_action_just_released("sword") and sword_obtained == true:

func pickup():
if Input.isactionjustpressed("take"):
obtained = true

func onArea2Dbodyentered(body):
if "pedestal" in body.name:

and BTW i'm new to this engine and gamedev stuff

in Engine by (25 points)

1 Answer

+1 vote

How is picking up the sword supposed to work? Because right now, it would only work if you enter a special area and press the "take" action at exactly the same time. It would probably be better if the body_entered and body_exited events would only set a flag like "is_sword_pickable" (set to true when entering, set to false when exiting). Then you can check for the "take" action in the _input function and add the sword only if is_sword_pickable is true.

by (1,756 points)

sorry but can u tell me how to use the exited function please

oh i figured it out
ok tnk u :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.