# A Physics doubt with speed and angle

Get help using Construct 2

### » Thu Apr 17, 2014 4:23 am

Hello Everyone,

Actually I am trying a basketball free throw 2d game. A simple character in the right, and the basket in the left end. My questions are...

1. When I mouse click or touch in the screen, the ball should comes towards my clicking position.
2. Based on how far and close I am clicking from the player, the ball should be fast and slow.

B
32
S
7
Posts: 197
Reputation: 2,537

### » Thu Apr 17, 2014 5:57 am

I have attached a rough example using the physics engine. When you click on the screen it will throw the ball towards your mouse, and the farther away you click the more force it will give the ball.

Let me know if you have any questions!
You do not have the required permissions to view the files attached to this post.
Visit me at EgoAnt.com
B
51
S
7
G
7
Posts: 81
Reputation: 6,419

### » Thu Apr 17, 2014 6:03 am

THanx
B
32
S
7
Posts: 197
Reputation: 2,537

### » Thu Apr 17, 2014 6:05 am

I missed one thing! Click on the ball and set the collision mask to "circle". Otherwise it will try to collide like a square and act a little silly.
Visit me at EgoAnt.com
B
51
S
7
G
7
Posts: 81
Reputation: 6,419

### » Thu Apr 17, 2014 6:18 am

THanx it what i need. BUt i cant figure out hot to set the Physics Force distance like you did
B
32
S
7
Posts: 197
Reputation: 2,537

### » Thu Apr 17, 2014 6:21 am

I used a simple distance calculation:
distance(Mouse.X,Mouse.Y,Ball.X,Ball.Y)

This will set the force directly to the distance from where the mouse was clicked (Mouse.X and Mouse.Y) to where the ball currently is.

You can adjust this force by multiplying it afterwards if you want.

Half the force: distance(Mouse.X,Mouse.Y,Ball.X,Ball.Y) * 0.5
Double force: distance(Mouse.X,Mouse.Y,Ball.X,Ball.Y) * 2
Visit me at EgoAnt.com
B
51
S
7
G
7
Posts: 81
Reputation: 6,419

### » Thu Apr 17, 2014 6:50 am

Awesome n tanx

Now I am trying it as a bullet. Created a simple canon and a bullet ball. Applied every actions to that bullet ball, but it is not working properly.

HOW TO DO THIS -

I want that canon to shoot a bullet with variable speed based on the distance of my mouse click.
B
32
S
7
Posts: 197
Reputation: 2,537

### » Thu Apr 17, 2014 8:03 am

If i remove the Physics force distance cmd and add

"Bullet-->Set bullet speed to Mouse X" it works fine. When I keep my mouse close enough to canon and click, the speed is less and if i click far away from the canon, the speed is quick.

BUT THIS IS ONLY FOR X

Ok. If i add Y "IT IS NOT WORKING"

B
32
S
7
Posts: 197
Reputation: 2,537

### » Thu Apr 17, 2014 9:26 am

Message: Harishankar is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Done Bro!!!!! Yes Found!!!!!

With the help of this thread

@EgoAnt & @caiorosisca Saved my day

Thanks a lot
Last edited by Madrasmadnes on Mon Jun 09, 2014 8:49 am, edited 1 time in total.
B
32
S
7
Posts: 197
Reputation: 2,537

### » Mon Jun 09, 2014 8:48 am

As I am testing in Mobile, when I change the mouse X and Y to Touch X and Y, the Bullet angle and speed does not work properly.

Where ever I touch, I goes in the same speed.

Why??

You do not have the required permissions to view the files attached to this post.
B
32
S
7
Posts: 197
Reputation: 2,537

Next

### Who is online

Users browsing this forum: No registered users and 16 guests