Hey i would need to create this dots. When you aim, the dots will show you where the arrow will probably fly.

9 posts
• Page **1** of **1**

Time for a physics lesson! The path that the arrow will follow is going to be a system of two equations, which we'll derive. From some basic trigonometry(and intuitive thinking), we know that the system of equations describing the motion of an arrow without gravity is:

Where x0 is the initial x position, y0 is the initial y position, s is the starting speed of the arrow, a is the angle the arrow makes with the X-axis, and t is the time -- in this case, in seconds. Since gravity is a factor as well, we need to take this into account as well. For an object that is merely falling from gravity, our equation for y is derived from acceleration due to gravity using calculus:

Where ay(t) is acceleration on the Y-axis, vy is the velocity on the Y-axis, g is acceleration due to gravity(a constant), and ' denotes a derivative of the preceding function identifier.

We can now add this to our initial system -- or rather, just y(t), since x(t) isn't affected by gravity -- to yield the system:

You can now figure out the position of the arrow at any point in time, so you could use a for loop -- for example, from 1 to 10, dividing the index by 10 to yield a time range of 0.1 to 1 seconds -- and generate dots representing the future position of the arrow at certain points in time.

In your case, g will be your arrow's gravity in pixels per second, and s will be the predicted speed of the arrow -- based on how far back it's pulled -- in pixels per second.

This should give you everything you need to implement such a system. I'll post an example later, but if you get it figured out before then, go ahead and post it so others can benefit.

- Code: Select all
`x(t) = x0 - cos(a) * s * t`

y(t) = y0 - sin(a) * s * t

Where x0 is the initial x position, y0 is the initial y position, s is the starting speed of the arrow, a is the angle the arrow makes with the X-axis, and t is the time -- in this case, in seconds. Since gravity is a factor as well, we need to take this into account as well. For an object that is merely falling from gravity, our equation for y is derived from acceleration due to gravity using calculus:

- Code: Select all
`ay(t) = g => ay'(t) = vy(t) = g * t => vy'(t) = y(t) = 0.5 * g * t^2`

Where ay(t) is acceleration on the Y-axis, vy is the velocity on the Y-axis, g is acceleration due to gravity(a constant), and ' denotes a derivative of the preceding function identifier.

We can now add this to our initial system -- or rather, just y(t), since x(t) isn't affected by gravity -- to yield the system:

- Code: Select all
`x(t) = x0 - cos(a) * s * t`

y(t) = y0 - sin(a) * s * t + 0.5 * g * t^2

You can now figure out the position of the arrow at any point in time, so you could use a for loop -- for example, from 1 to 10, dividing the index by 10 to yield a time range of 0.1 to 1 seconds -- and generate dots representing the future position of the arrow at certain points in time.

In your case, g will be your arrow's gravity in pixels per second, and s will be the predicted speed of the arrow -- based on how far back it's pulled -- in pixels per second.

This should give you everything you need to implement such a system. I'll post an example later, but if you get it figured out before then, go ahead and post it so others can benefit.

**Posts:**1,586**Reputation:**19,116

Moderator

B

113
S

41
G

20
**Posts:**256**Reputation:**15,125

B

74
S

28
G

17
^The link just above had some great code, taking into account C2 physics.

I put something together in a hurry in an attempt to help. It may just confuse you more and be needlessly complicated, but, drag the red dot, then release:

http://arrall.com/c2/motionmarkers

Something like that?

I looked at your capx. Nice what you've done with the bow, string, and arrow. The arrow travels rather fast with minimal drawing of the bow.

I put something together in a hurry in an attempt to help. It may just confuse you more and be needlessly complicated, but, drag the red dot, then release:

http://arrall.com/c2/motionmarkers

Something like that?

I looked at your capx. Nice what you've done with the bow, string, and arrow. The arrow travels rather fast with minimal drawing of the bow.

You do not have the required permissions to view the files attached to this post.

**Posts:**37**Reputation:**524

B

6
S

2
Thank you very much i will take a look,

And the bow and arrow it wouldnt be possible with help of the community here, If you liked it , try this.

https://dl.dropboxusercontent.com/u/84146142/WebGame11/index.html

And the bow and arrow it wouldnt be possible with help of the community here, If you liked it , try this.

https://dl.dropboxusercontent.com/u/84146142/WebGame11/index.html

**Posts:**419**Reputation:**1,782

B

11
S

3
G

1
**Posts:**401**Reputation:**22,282

B

117
S

49
G

24
I'd like my fish sprite to leap out of the "water" and then arc back into the "water"

at the moment most of the action is below the water line and I'm happy with the 8 direction control I have. If I swim to the surface I'd like to jump out at the angle and speed of exit and come back down at an arc.

Thought please

Alister from New Zealand

at the moment most of the action is below the water line and I'm happy with the 8 direction control I have. If I swim to the surface I'd like to jump out at the angle and speed of exit and come back down at an arc.

Thought please

Alister from New Zealand

**Posts:**2**Reputation:**750

B

15
S

2
9 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: tarek2, Yahoo [Bot] and 20 guests |