Jump to content
  • Advertisement
Sign in to follow this  
amateur programmer

Guided missle

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to be able to fire a missle from x1 y1 so that it hits x2 y2. But I want it to have it's speed as a variable. I am using SDL to paint my missle onto the screen. I'm not sure how I would do that. Something to do with good old trigometry which i cant remeber any of. I want to be able to dodge this thing.

Share this post


Link to post
Share on other sites
Advertisement
Let me see if I've got a good idea of what you are doing.

You want a missile. which will be launched at some finite speed. once launched, it will have inertia. It will also have a direction that it is facing, which because of the inertia, will be independant of the direction it is moving in. It will accelerate constantly in the direction it is facing, except when it is facing away form the enemy. It will always try to turn to face towards the enemy. IT will explode on impact.

Have I got it right? I wnat to make sure I've got everything your thinking before I start spouting algorithms.

Share this post


Link to post
Share on other sites
Sorry guys didn't explain it well. Basically by variable speed i mean i can specify it within a variable. Reason is it cant be traveling too fast otherwise the player wont even have a chance to move before it hits him. It doesn't have an inertia sorry my fault. IT will attempt to calculate the angle which the missle should be fired at in order to hit the player. When it's fired it then travels in a straight line at calculated angle. It's speed is a constant value.

Share this post


Link to post
Share on other sites
Well then, use a vector velocity: v = speed×(rplayer-rlauncher); r's are position vectors. Each frame you just adjust the missile's position based on its velocity.

Share this post


Link to post
Share on other sites
Ok maybe am jumping the gun again lol. Only recently started game programming so I never heard of position vectors. How do I use/declare them Am using SDL as my API. Perhaps a tutorial on it because it's better than u just giving me the code. I dont learn anything that way.

Share this post


Link to post
Share on other sites
You need to read up on vectors in general. Then you'll know what a vector is, and what a position vector is.

Then you can figure out how to give the missile a velocity vector as well as a position vector, and use (in practice) euler integration to handle its motion. This will enable you to have a consistent model of motion between different objects in your game, which is a Good Thing.

Mark

Share this post


Link to post
Share on other sites
so say the result of the vector subtraction was [5,4,3] do I just multiply each number by speed.

Position vectors: The position vector of a point A is simply the vector from the origin O = (0,0,0) to point A = (Ax,Ay,Az). The position vector of point A is A = (Ax-0,Ay-0,Az-0) = (Ax,Ay,Az).

MY position vector will just contain x and y codinates of both enemy and the player right? But what about the direction? But basically it's a point on the screen am refering to. I thought a vector is a directed line with magnitude and direction. Am confused??????

Share this post


Link to post
Share on other sites
In mathematical terms, a vector can represent many things, including a position and a direction/magnitude.

There are a few ways of getting the result you are looking for. Here is one.

The angle of the direction that the missile travels can be found using the arctangent. Specifically,
    angle = atan2( y1-y0, x1-x0 ); 
The location of the missile at any time can be now be determined.
    mx = x0 + speed * time * cos( angle );
my = y0 + speed * time * sin( angle );
You can also do the following if you use the time since the last update instead of the overall time:
    mx += speed * time * cos( angle );
my += speed * time * sin( angle );

Share this post


Link to post
Share on other sites
There have been some topics on this in the past. Although, it sounds like you are going to work on the basics more first. Anyhow, when you are ready, you might read these for some reference material or ideas on guided missiles others have provided.
click1
click2
click3
(Also use the search tool above - there should be more.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!