Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (622) 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 1649 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: 374
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: 374
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.

 BurntPizza (27 views) 2015-04-23 03:42:11 theagentd (31 views) 2015-04-22 16:23:07 Riven (44 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (62 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x kingroka123 11x alwex 11x 65K 11x Rayvolution 10x kevglass 8x phu004 8x KevinWorkman 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x
 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