#### Archived

This topic is now archived and is closed to further replies.

# Shooting Geometry in VB

This topic is 5309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, im making a sorta worms clone and have am ready to implement the shooting geometery, only problem is i have no idea how to do it. im not the best with physics (i know some basic stuff, although it doesnt really apply to the game i got so far. lol). i have gravity implemented as 50 "twips" (im just using the VB environement with cheap graphics for now due to my time limit to finish the game, 2 weeks) per second(or every refresh period). In order for the user to shoot they must enter an angle (between 0-180) and power(between 0-100%), Now the biggest problem im having is how to "project" the ball at the user entered angle, also im not 100% sure about how to implement the power but i could figure that part out after. so if anyone knows how to make the ball shoot at the desired angle please let me know, it would be a big help. Or if your really feeling generous you could tell me how to implement the power aswell =P. lol. thanks alot

##### Share on other sites
C''mon someones gotta know how to do it. i know its only been a little bit but i need to get this done, sorry if i seem obnoxious or anything here. lol

##### Share on other sites
Given the users selected angle, calculate the x and y velocities like so:
/|
/ |
v / |
/ |y
/O |
------
x
x = vcos(o), y = vsin(o)

Now it''s just a matter of keeping track of those values. With no air resistance, the x velocity should remain constant. The y velocity will be changed by the gravitational force, so it will always be changing.

As for power, you just assign that as a percentage of v, I suppose. So if the user chooses 100%, the initial velocity is v. If they chose 50%, the initial velocity of the projectile is 0.5*v, etc.

Hope this helps some.

##### Share on other sites
/|
/ |
v / |
/ |y
/O |
------
x
(Let''s hope this looks more presentable)

##### Share on other sites
Oh well, I give up. Just draw a right triangle with the vertical part labelled y, the horizontal part, x, and the hypotenuse, v. The angle between v and x is "o".

##### Share on other sites
ok, where would the x and y values come from? would it just be like the form width and height??

[edited by - TwisteR on May 30, 2004 8:07:08 PM]

##### Share on other sites
The x and y labels (as above) are the x-velocity and y-velocity of the projectile (calculated from the initial velocity v, which is, effectively, the power of the shot). If you keep track of both of these, moving the projectile is a simple matter of updating the missile''s position based on these x and y velocities, and then applying changes the the velocities (i.e. gravity will continually be added to the y-velocity).

So, if the user chooses 100% power and 45 degree angle, you say that the initial velocity v will be v = 100 twips/second and the initial x and y velocities will be x = 100 * cos(45) and y = 100 * sin(45). After this, the angle of the projectile is inconsequential to calculations. If you assume no air resistance, the value of x never changes. For y, you would subtract your decided value for gravity each frame (or each second, depending on how you are controlling the movement of objects with respect to frame rate).

##### Share on other sites
The power and angle are combined to get the initial velocity, using the formula the AP gave you:
initial x velocity = power * cos(angle)
initial y velocity = power * sin(angle)
The y velocity you''ll probably want to invert because the coordinates on the computer screen are from the top down. Then on every frame you move the missile by the x and y velocity, and then calculate the effect of gravity on the y velocity, and of wind and air drag, etc. on both velocities.

shmoove

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013390
×