Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (607) 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 1623 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: 367
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: 367
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

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

 Riven (9 views) 2015-04-01 18:27:05 ags1 (24 views) 2015-03-31 10:55:12 theagentd (13 views) 2015-03-27 23:08:20 wxwsk8er (54 views) 2015-03-20 15:39:46 Fairy Tailz (48 views) 2015-03-15 21:52:20 Olo (29 views) 2015-03-13 17:51:59 Olo (33 views) 2015-03-13 17:50:51 Olo (40 views) 2015-03-13 17:50:16 Olo (44 views) 2015-03-13 17:47:07 ClaasJG (61 views) 2015-03-10 11:36:42
 BurntPizza 21x LiquidNitrogen 21x KevinWorkman 18x EgonOlsen 17x theagentd 16x basil_ 16x Roquen 15x Varkas 12x wessles 11x 65K 11x Riven 9x Rayvolution 9x phu004 8x princec 8x SHC 8x Ashedragon 8x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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