How do I appear a arrow show the direction of the ball ?

Get help using Construct 2

» Thu Nov 06, 2014 3:22 pm

Hi
How do I appear a arrow show the direction of the ball before i release it ? like what we see in games like billiards
You do not have the required permissions to view the files attached to this post.
B
4
S
1
Posts: 18
Reputation: 395

» Thu Nov 06, 2014 4:10 pm

You need a mathematical equation to calculate the angle of arrow. as an example if your ball is a "Sprite" and stick's position is mouse pointer then angle of arrow is : "atan((Mouse.Y-Sprite.Y)/(Mouse.X-Sprite.X))". "atan" it teturn the inverse Tangent angle value between mouse pointer and ball
B
24
S
2
G
1
Posts: 46
Reputation: 1,112

» Thu Nov 06, 2014 4:22 pm

Hey AeleaS,

Two possibilities come to mind that might work.

To set the angle of the arrow, you can either use the "Set angle towards position" action, or you can just use the "Set angle" action and as the parameter use a handy built in system expression in Construct2 called angle() which will get the angle between two points.
e.g.
• angle( 0 , 0 , 100 , 100) = 45
• angle( Obj.X , Obj.Y , Mouse.X , Mouse.Y ) = The angle of a line from Obj to Mouse.

Fixed length arrow - (uses one sprite)
1. Create a sprite arrow pointing right (0 degrees).
2. Place the hotspot at the tail of the arrow. (This should be the middle of the left edge of the image.)
3. Set the arrow sprite to the position of the billiard ball (or whatever you're interacting with), and set the angle of the arrow to the angle you want.

e.g. Below I'll assume we want the arrow to go from a billiard ball to the mouse cursor.

Event:
* Every Tick.
Actions:
* Set Arrow to position of BilliardBall.
* Set Arrow angle to look at coord ( Mouse.X , Mouse.Y ).

Resizable length arrow - (uses two sprites)
To create an arrow that can change length, you can create the arrow in two parts.
1. Create the tail, by making a simple 4x4 pixel block filled with a solid color.
2. Place the hotspot at the left center edge of this sprite.
3. Create an image point named "headAttachPoint" at the right center edge.
4. Now create a new sprite that looks like an arrow head pointing right, and place the hotspot at the left edge.
5. Put the Arrow tail and arrow head sprites in a Construct2 "container".
6. In the event editor add the following events:

e.g. Below I'll assume we want the arrow to go from a billiard ball to the mouse cursor.

Event:
* Every Tick.
Actions:
* Set ArrowTail to position of BilliardBall.
* Set ArrowTail angle to look at coord ( Mouse.X , Mouse.Y ).
* Set ArrowTail width to distance( Self.X , Self.Y , Mouse.X , Mouse.Y ) // This sets the arrow length.
* Set ArrowHead angle to ArrowTail angle.

Hope that helps out.
B
30
S
20
G
8
Posts: 349
Reputation: 6,475

» Thu Nov 06, 2014 4:35 pm

Hi AeleaS, like this ?
angle.capx

edit : Oh, fisholith, that's a reply
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276