hmm lemme think..
the angle could be easily achieved with sin(angle)*X for the change in upwards motion... but there is alot I don't know about quadratic equation, they only taught me to change it from trinome to binome..
It migh tlook something like:
Y = -X^2+(sin(angle)*X)+StartPointOfShot
note: this probably won't do gravity very well.. post this in the maths forum.
Don't pay attention to this signature, it's contradictory.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Hmm... Try this:
VB Code:
'To get the projectile moving
Gravity = 0.5
ShootSpeed = 10
X = 100
Y = 100 'These are just sample coordinates, where the projectile starts...
XSpeed = cos(Angle) * ShootSpeed
YSpeed = sin(Angle) * ShootSpeed
'Every frame
YSpeed = YSpeed + Gravity
X = X + XSpeed
Y = Y + YSpeed
These are untested values, you'll have to experiment with those to get the result you want
Oh, and be careful with the variables' scope and put the Every Frame code in a timer or something, the other code in the Form_Load or something like that...
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
Since games use a step-by-step simulation and not immediate calculation it's actually very straight forward:
1) Slow down the overall speed of the projectile by a constant factor (drag).
2) Increase the down-part of the speed of the projectile by a constant factor (gravity).
3) Modify the projectile position with the speed vector.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Duh it's the same thing except for the drag. Ok. I never used drag and it always worked really well, why would you need to slow down the projectile like that? With most projectiles air resistance is almost non-existant, what else do you need...
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
Originally posted by Jotaf98 Duh it's the same thing except for the drag. Ok. I never used drag and it always worked really well, why would you need to slow down the projectile like that? With most projectiles air resistance is almost non-existant, what else do you need...
Huh? Never fired a rifle then, eh? Fire off a 22-250 - at the muzzle it's moving at about 4000 ft. per sec.. At 1000 yards it's moving at about 2000 ft. per sec.. What's slowing it down?
Originally posted by Sheppe Huh? Never fired a rifle then, eh? Fire off a 22-250 - at the muzzle it's moving at about 4000 ft. per sec.. At 1000 yards it's moving at about 2000 ft. per sec.. What's slowing it down?
Ever seen a game with a line of sight of 1000 yards? Ill give you Delta Force, however, drag is included in the Delta Force calculations, if I recall correctly. Most of the time, its irrelevent, and most often, gunshots are reduced to simple ray casts, and damage is applied instantly.
Was just the general projectile formula. Could also be a stone or a ball threwn. And some balls have a LOT air resistance.
To make it even better you'd even have to calculate in the wind, but not many games have wind at all. But if you write a Worms-like game you should know about it.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Y = 100 'These are just sample coordinates, where the projectile starts...
XSpeed = cos(Angle) * ShootSpeed
YSpeed = sin(Angle) * ShootSpeed
'Every frame
YSpeed = YSpeed + Gravity
X = X + XSpeed
Y = Y + YSpeed
These are untested values, you'll have to experiment with those to get the result you want
Oh, and be careful with the variables' scope and put the Every Frame code in a timer or something, the other code in the Form_Load or something like that...
this code... hahaha
actually i fixed it a bit, but now it just goes on a diagonal down the screen.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Huh... the "To get the projectile moving" part is meant to be used ONCE (to get the projectile moving ), the "Every frame" part is every frame...
If you're using a control, you should also at the end of every frame do this:
VB Code:
obj.Left = X
obj.Top = Y
But of course that's a bit obvious, isn't it?
Oh you also need to declare the variables... (as Single or something) anything else?
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
You're right Sas but I think that his problem was that he was running the whole code every frame (so the variables were reset every frame).
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
Dim x, y, shootspeed, gravity, angle, xspeed, yspeed As Single
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
'To get the projectile moving
gravity = 0.5
shootspeed = 10
angle = 1
x = 100
y = 100 'These are just sample coordinates, where the projectile starts...
xspeed = Cos(angle) * shootspeed
yspeed = Sin(angle) * shootspeed
End Sub
Private Sub Timer1_Timer()
'Every frame
yspeed = yspeed + gravity
x = x + xspeed
y = y + yspeed
Shape1.Left = x
Shape1.Top = y
End Sub
When this is run the shape just drops off to the bottom, and doesnt seem to come back up
hey cornbee perhaps you should explain how to slow down the overall velocity when using vx and vy as variables, when i got tired with it, i wrote a complete 2d vectors module for it. any better way ??
You need a quadratic equation for this.
Here's a basic explanation.
A quadratic equation is an equation used to make a parrabolic curve on a graph, I know it can be used for this because they use them in astronaut training to simulate 0g gravity.
It has a basic format: ax^2 + bx + c
a will change how sharp the curve is, c will change the starting height and b changes a bit of everything... here is an example
Oh, and if a is negative, the cuve will face down instead of up, which is VERY important hehe..
-1x^2 + 4x + 25 I am going to simplify this quadratic equation
-1(x^2 - 4x) + 25 First I put x^2 and 4x in paranthese (4x\-1=-4x)
-1(x^2 - 4x +4-4)+25 Then I do (b/2)^2, add + subtract it inside ()
-1(x^2 - 4x + 4) + 25 +4 Take -4, divide it by -1 and get it out of ()
-1(x-2)^2 +29 Get rid of -4x+4, move the ^2 so that it affects the whole ()
and change -4x + 4 to - half of b (4/2=2)
-1(x-2)^2 +29 so what's the point of doing this? Well I can tell you that the projectile will hit it's maximum height at (2, 29), now where did I get those numbers.. hmmm
-1(x-2)^2 +29
All you have to do is change -1 for sharpness of the curve, -2 for where it hits maxY on X axis (x = -2*-1) and 29 is where it maxes on Y axe.
Don't pay attention to this signature, it's contradictory.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Yeah I know that alkatran (that was today's topic for our math class) but it's not that useful if you want to calculate it every frame. My method is fine, but your code needs a few changes: first, that angle throws the shape almost directly to the bottom of the screen, so of course you don't notice any difference, make the angle 5 or something; second, I gave you everything in pixels and it doesn't work if your form is set to twips... (I tried it with these changes and it worked fine )
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
Alkatran: as Jotaf said, your code is nice to plot a trajectory curve or to calculate where a projectile hits, but we're talking about simulation here.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
No. Then speed would be only horizontal speed. What if the projectile was fired at an angle?
And it's useless calculation. Nobody wants that in a game loop.
The 5*X part should be removed. It's not useful for trajectory.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
One more thing CornBee,
The drag MUST be proportional to the square of the velocity
DragForce=-k*v*v
Acc=DragForce/mass
v=v-Acc
vx=v*cos(Angle)
vy=v*sin(Angle)+gravity
v=sqr(vx*vx+vy*vy)
if vx<>0 then
Angle=Atn(vy/vx)
End if
posX=posX+vx
posY=posY + vy
Last edited by anjulpa; Jan 8th, 2003 at 09:24 AM.
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Yeah so I guess it's solved
One more thing. I noticed you said that it "doesn't come back up". So you want it to bounce when it hits the ground? To do that, you'll have to add this check:
VB Code:
'Basically we're checking if the shape has hit the bottom of the
'form, you can of course use the variables X and Y or something
'else than the form's height to check this, you can for example
'make it bounce on walls and stuff...
If Shape1.Top + Shape1.Height > Form1.ScaleHeight * 15 Then
'Invert the Y speed, so it starts moving up instead of down, and multiply it by 0.75 to decrease it a bit (or it wouldn't lose velocity with the hit and would never stop bouncing)
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Hey hey looks like I'm a frenzied member now... cool
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."