Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (757) Games in Android Showcase (229) games submitted by our members Games in WIP (844) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Vector acceleration based on angle?  (Read 2966 times) 0 Members and 1 Guest are viewing this topic.
CyanPrime
 « Posted 2011-06-02 03: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).

ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #1 - Posted 2011-06-02 04: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.

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

Thank you.
dishmoth
 « Reply #3 - Posted 2011-06-02 05: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.

ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #4 - Posted 2011-06-02 06: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

 EgonOlsen (79 views) 2018-06-10 19:43:48 EgonOlsen (59 views) 2018-06-10 19:43:44 EgonOlsen (78 views) 2018-06-10 19:43:20 DesertCoockie (261 views) 2018-05-13 18:23:11 nelsongames (160 views) 2018-04-24 18:15:36 nelsongames (158 views) 2018-04-24 18:14:32 ivj94 (901 views) 2018-03-24 14:47:39 ivj94 (162 views) 2018-03-24 14:46:31 ivj94 (813 views) 2018-03-24 14:43:53 Solater (177 views) 2018-03-17 05:04:08
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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