0 votes

here is my script plz helpmee

const MOVE_SPEED = 100
const JUMP_FORCE = 350
const GRAVITY = 45
const MAX_FALL_SPEED = 950

onready var anim_player = $AnimationPlayer
onready var sprite = $Sprite

var y_velo = 0
var facing_right = true

func _physics_process(delta):
    var move_dir = 0
    if Input.is_action_pressed("move_right"):
        move_dir += 1
    if Input.is_action_pressed("move_left"):
        move_dir -= 1
    move_and_slide(Vector2(move_dir * MOVE_SPEED, y_velo), Vector2(0, -1))

    var grounded = is_on_floor()
    y_velo += GRAVITY
    if grounded and Input.is_action_just_pressed("jump"):
        y_velo = -JUMP_FORCE
    if grounded and y_velo >= 5:
        y_velo = 5
    if y_velo > MAX_FALL_SPEED:
        y_velo = MAX_FALL_SPEED

    if facing_right and move_dir < 0:
        flip()
    if !facing_right and move_dir > 0:
        flip()

    if grounded:
        if move_dir == 0:
            play_anim("Idle")
        else:
            play_anim("Walk")
    else:
        play_anim("Jump")

func flip():
    facing_right = !facing_right
    sprite.flip_h = !sprite.flip_h

func play_anim(anim_name):
    if anim_player.is_playing() and anim_player.current_animation == anim_name:
        return
    anim_player.play(anim_name)
in Engine by (16 points)

1 Answer

0 votes

Check the documentation for InputEventMouseButton
For a simple answer you could create a new _input handler like:

func _input(event):
    if event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and event.pressed:
    anim_player.play(..

It's also worth learning how to use InputMap to properly handle inputs from different sources. I think all of this is quite well covered in the docs, do make sure to follow the tutorials there, learning how to search and navigate the documentation will help you learn the engine much more quickly :) Good luck!

by (94 points)

i got an error it says

Invalid get index 'type' (on base: 'InputEventMouseMotion').

nevermind i fix it, THANK YOU!!!

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.