Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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  
  Vector acceleration based on angle?  (Read 1103 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2011-06-02 05:10:26 »

How can I accelerate something yet have it move in it's angle?

1  
2  
Vector2f pos = new Vector2f(250,250);
float angle = 145;


Now I also got velo and accel
1  
2  
Vector2f velo = new Vector2f(0,0);
Vector2f accel = new Vector2f(1,1);


Now to accelerate I add accel to velo, then each time I move by adding velo to pos, but how do I make it so velo takes the angle into account? for example if you were to be at angle 45 and press the go button you would start moving at a velo of (1,-1) and that velo would be increased by (1,-1) for each pass that you hold the go button; However, if you were at angle 145 the velo and increase would be (1,1).


Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2011-06-02 06:38:14 »

You should instead have a speed variable. Velocity is speed + angle (by using the deltaX and the deltaY). If you want a velocity vector, all you need to do is add the acceleration to it, then add it to the position. Otherwise, you could have a speed and angle variable and use trig to find the deltaX and deltaY:
1  
2  
pos.x += velocity * Math.cos(Math.toRadians(angle));
pos.y += velocity * Math.sin(Math.toRadians(angle));


EDIT: Fixed the wording. Cheesy

Offline CyanPrime
« Reply #2 - Posted 2011-06-02 06:58:09 »

Thank you. Grin
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline dishmoth
« Reply #3 - Posted 2011-06-02 07:50:23 »

Velocity is a scalar value. You don't see 2 different speedometers while driving a car do you?
You should probably read up on the difference between speed and velocity.

Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #4 - Posted 2011-06-02 08:24:52 »

Velocity is a scalar value. You don't see 2 different speedometers while driving a car do you?
You should probably read up on the difference between speed and velocity.
Ah yes thank you, I misused the terms.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (29 views)
2013-05-17 21:29:12

alaslipknot (39 views)
2013-05-16 21:24:48

gouessej (69 views)
2013-05-16 00:53:38

gouessej (68 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (72 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (136 views)
2013-05-12 17:10:36

kutucuk (136 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.091 seconds with 21 queries.