I'm making a game and I need to know the physics of an arrow's arc the air like in this project. I tried downloading that one but it was hard to understand with all the lists and scripts for the target in there too.
Can anyone help?
Offline
You use x- and y-velocity. Taking the arctangent of (Velocity.Y) / (Velocity.X) will give you the angle of motion (although, you'll have to take 90 - (angle) to convert it to Scratch degrees). However, the arctangent function doesn't work when x-velocity = 0 (dividing by 0). You have to manually catch that one and tell the program what the value of the direction should be so that it doesn't freeze up. Basically, you have a script like this:
when gf clicked set [Acceleration.Gravity v] to [-0.2] // Choose a value forever change [Velocity.Y v] by (Acceleration.Gravity) change [Position.X v] by (Velocity.X) change [Position.Y v] by (Velocity.Y) point in direction ((90) - ( [atan v] of ((Velocity.Y) / (Velocity.X)) )) physics scripts... go to x: (Position.X) y: (Position.Y)
Last edited by amcerbu (2012-07-17 01:45:03)
Offline
amcerbu wrote:
You use x- and y-velocity. Taking the arctangent of (Velocity.Y) / (Velocity.X) will give you the angle of motion (although, you'll have to take 90 - (angle) to convert it to Scratch degrees). However, the arctangent function doesn't work when x-velocity = 0 (dividing by 0). You have to manually catch that one and tell the program what the value of the direction should be so that it doesn't freeze up. Basically, you have a script like this:
when gf clicked set [Acceleration.Gravity v] to [-0.2] // Choose a value forever change [Velocity.Y v] by (Acceleration.Gravity) change [Position.X v] by (Velocity.X) change [Position.Y v] by (Velocity.Y) point in direction ((90) - ( [atan v] of ((Velocity.Y) / (Velocity.X)) )) physics scripts... go to x: (Position.X) y: (Position.Y)
So basically, (not in scratch,) to add the effect of of an arrow's arc (without gravity playing a part yet), I do
< [atan v] of ((Velocity.Y) / (Velocity.X))>I don't know what atan is/what it does, but I'll see if this works.
Last edited by TorbyFork234 (2012-07-17 01:52:59)
Offline
It works amazingly! Thanks!
Offline
"atan" is short for arctangent. It's an inverse trigonometric function. The tangent function normally takes an angle measure and returns a slope (ΔY / ΔX). The arctangent function takes a slope value and returns an angle. You use it to "convert" between x and y velocity movement and directional movement.
The part that adds gravity is the "change Velocity.Y by Acceleration.Gravity."
Offline
amcerbu wrote:
The part that adds gravity is the "change Velocity.Y by Acceleration.Gravity."
I could tell that, the only thing I didn't understand with your scripts was the atan part.
Also, it get funky with Velocity.X=10, Velocity.Y=10, and Velocity.X=Velocity.X*0.9. It curves upwards then drops down.
Offline
TorbyFork234 wrote:
amcerbu wrote:
The part that adds gravity is the "change Velocity.Y by Acceleration.Gravity."
I could tell that, the only thing I didn't understand with your scripts was the atan part.
Also, it get funky with Velocity.X=10, Velocity.Y=10, and Velocity.X=Velocity.X*0.9. It curves upwards then drops down.
That's a pretty strong coefficient...try something more like .95 and the difference will be pretty visible..just think about it:
1: .9 and .95
2: .81 and .9025
3: .729 and .857375
4: .6561 and .81450625
and so on... using just a little higher coefficient makes a big difference.
Offline
amcerbu wrote:
^^ That's true. In fact, you might even want something like 0.99 or 0.999 if you don't want the arrow to slow down too terribly fast.
I know that, I'm just saying that when the coeffiecent is 0.9 it's completely weird. Also, I can't upload it right now amercbu.
Last edited by TorbyFork234 (2012-07-18 00:22:26)
Offline
TorbyFork234 wrote:
amcerbu wrote:
^^ That's true. In fact, you might even want something like 0.99 or 0.999 if you don't want the arrow to slow down too terribly fast.
I know that, I'm just saying that when the coeffiecent is 0.9 it's completely weird. Also, I can't upload it right now amercbu.
Are you sure you didn't accidentally set it to -.9? Because that would make it pretty much stay in one place while rising and falling.
Offline
@AtomicBawm3, I'm completely sure.
@amcerbu, I'm trying to make it scroll, with a lot of power, so adding in friction will make a difference on that large scale.
Offline