Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shots in different directions - assign correct velocity  (Read 1051 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2011-07-07 09:46:25 »

This one is pretty simple, and it's found in many games.  persecutioncomplex The simplest one being asteroids.
The ship is rotating, and shooting - but how do I find out how much X/Y-velocity I need to assign a bullet, in order for it to fly as if it
was shot from the nose of the ship?

Thanks in advance  Smiley

Offline pitbuller
« Reply #1 - Posted 2011-07-07 10:32:08 »

How about sin and cos.
dX = cos(angle in radians)
dY = sin(angle in radians)

Then you can add your vehicle velocities to ammo velocities. Also you should count law of conservation of linear momentum for realism.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #2 - Posted 2011-07-07 11:15:54 »

How about sin and cos.
dX = sin(angle in radians)
dY = sin(angle in radians)

Then you can add your vehicle velocities to ammo velocities. Also you should count law of conservation of linear momentum for realism.

dY = cos(angle in radians)
Right? Or both sin? Shocked

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
« Reply #3 - Posted 2011-07-07 11:23:43 »

dX = cos(angle in radians)
dY = sin(angle in radians)
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #4 - Posted 2011-07-07 11:45:49 »

I've just started looking at this, this morning (never learned this in school - I'm 16).
Now, due to wonderful articles on the interwebs the learning of those two functions were smooth. In located in Denmark though, so the technical terms is different. Radian.

That is called "angle" here.. I think. Is it correct to say theres 360 radian in a circle?
A flat line has 180 radian? Never heard the term before, in english.


EDIT: Just looked it up. Appearently, 0 radian is a flat line. Does Java measure rotations in radian or degrees then?

Offline pitbuller
« Reply #5 - Posted 2011-07-07 12:10:53 »

Full circle is 2*pi radians or 360 degrees.
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Math.html#sin%28double%29
Javadocs for sin and cos. If you are unfamiliar with radians use toRadians and toDegrees functions.
Offline Salonika

Junior Newbie




while(alive) { code; play; }


« Reply #6 - Posted 2011-07-07 16:28:31 »

a trick i used when i developed an asteroids clone is to advance the position of the bullet by 2 or 3 frames harcoded so that it has reached the ships perimeter
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (36 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!