0 votes

I am working on a simple 3D beer pong game. Currently, I have it working and the apply_impluse function sends the ball flying into the cup. But I was wondering if there is a way to be able to throw the ball using a mouse gesture or screen drag.

in Engine by (12 points)

There's an option in input to check for a screen drag. I would elaborate more, however, I'm on mobile.

1 Answer

0 votes

What kind of gesture are we talking here? If its enough with one swipe to get a force to multiply apply_impulse with, you can simply get the speed parameter from the input event.

extends ...

var force = 0
func _input(event):
    event.speed
    if event is InputEventScreenDrag:
        force = event.speed
by (997 points)

Hey! So the gesture would be like a click and drag (or swipe for touch screen) for a throwing the ball. My current code looks like this,

func _on_Ball_input_event(camera, event, click_position, click_normal, shape_idx):
    event.speed
    if event.is_action_pressed("Click"):
            print("Pressed")
            force = event.speed

I tired implmeting this, but i get the error Invalid get index 'speed' (on base: 'Input EventMosueButton')

Over all, I want the user to beable to click and drag the ball like a throwing action, then eventually add touch screen support.

Well, I figured out what i was doing wrong.

if event is InputEventMouseMotion:
    print("Motion")
    force = event.speed
    print(force)

This works to get said speed variable!

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.