Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Missile Shooting
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
evildaddy911




PostPosted: Tue Dec 06, 2011 4:58 pm   Post subject: Missile Shooting

A while ago I was making a top-down game, and I kept thinking, "Is there a way that I can use x and y velocities and still keep a constant speed no matter what angle I am shooting at?"

So I did some tinkering and came up with this:

Turing:
xv := (x2 - x1) / (Math.Distance (x1, y1, x2, y2) / speed)
yv := (y2 - y1) / (Math.Distance (x1, y1, x2, y2) / speed)


(x1 and y1 are the coordinates of where the bullet is being shot from, and x2 and y2 are the coordinates to where the bullet is headed)

Then you simply add the current x/y coordinates to their respective velocities to determine where the bullet will be next frame.

PLEASE NOTE:
In order to ensure accurate results, use real values for the current x, y, xv and yv values and use the round() function

Here's a simple example of how this can be used:



draw missile.t
 Description:
simple example of a bullet being shot between 2 balls

Download
 Filename:  draw missile.t
 Filesize:  1.1 KB
 Downloaded:  226 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Dec 06, 2011 7:19 pm   Post subject: RE:Missile Shooting

That does work. Another way I found to be useful was to use trigonometry instead.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: