Java-Gaming.org Hi !
 Featured games (88) games approved by the League of Dukes Games in Showcase (681) Games in Android Showcase (196) games submitted by our members Games in WIP (744) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Shooting at angles at constant velocity.  (Read 1678 times) 0 Members and 1 Guest are viewing this topic.
cubemaster21
 « Posted 2012-04-17 02:01:37 »

I honestly have no idea where to begin with coding this. I want to be able to move something at the same speed, no matter what angle. No matter if it's 45* or 23*. Any help?

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
sproingie

JGO Kernel

Medals: 202

 « Reply #1 - Posted 2012-04-17 02:05:37 »

I don't quite understand.  Velocity should be constant regardless of direction.  If you're looking to break the x and y components out to see how much to displace something based on a velocity, just multiply by sin and cosine, like so:

dx = velocity * cos(angle)
dy = velocity * sin(angle)

Keep in mind angles are usually in radians, not degrees.  OpenGL being the exception when using the fixed function pipeline.

cubemaster21
 « Reply #2 - Posted 2012-04-17 02:08:09 »

Well, the reason it might not make sense is because i've been using slope to move around the character.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
DrZoidberg

JGO Coder

Medals: 19

 « Reply #3 - Posted 2012-04-17 02:17:50 »

If you already have a dx and dy and want to change the speed you can do this
 1  2  3 `double speed = Math.sqrt(dx*dx + dy*dy);dx = dx / speed * newSpeed;dy = dy / speed * newSpeed;`
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 CopyableCougar4 (55 views) 2016-06-25 16:56:52 Hydroque (89 views) 2016-06-22 02:17:53 SwampChicken (90 views) 2016-06-20 13:22:57 SwampChicken (92 views) 2016-06-20 13:22:49 SwampChicken (85 views) 2016-06-20 13:22:26 Hydroque (129 views) 2016-06-15 08:22:50 Hydroque (123 views) 2016-06-13 06:40:55 DarkCart (240 views) 2016-05-29 02:30:33 Hydroque (206 views) 2016-05-26 14:45:46 Mac70 (188 views) 2016-05-24 21:16:33
 Spasi 49x theagentd 45x NegativeZero 39x KaiHH 30x LiquidNitrogen 23x princec 19x CoDi^R 16x ra4king 13x ags1 12x kingroka123 10x Opiop 10x purenickery 9x Hydroque 8x TritonDreyja 8x Archive 8x SHC 8x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 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