My Math Forum  

Go Back   My Math Forum > High School Math Forum > Algebra

Algebra Pre-Algebra and Basic Algebra Math Forum

LinkBack Thread Tools Display Modes
February 9th, 2012, 03:00 PM   #1
Joined: Feb 2012

Posts: 2
Thanks: 0

incease speed and changing direction.

i'm a game developer not so good in maths
so i thought i come ask some advice here...

what i basically need is a formula that can increase in both positive and negative with using one variable that changes from minus to plus.

my code is this

speed +=1
speed= -speed

the problem here off course is that is does the following on update:

speed = 5 + 1
5+1 = -(5+1)
which is good (my object changes direction and goes 1 faster)
then the second time

speed = -6 +1
-5 = 5
my direction changes but my speed goes down one...

now is there a way i can get the number increased in the part where it says speed = -6 +1 so it results in - 7 and the next run would be 7+1 and so on...?
don't even know if this is a stupid question or not i just can't figure out how to get it to work with in one formula...

so any pointers are welcome
thx J.
rottjung is offline  
February 9th, 2012, 03:17 PM   #2
Senior Member
MarkFL's Avatar
Joined: Jul 2010
From: St. Augustine, FL., U.S.A.'s oldest city

Posts: 12,193
Thanks: 504

Math Focus: Calculus/ODEs
Re: incease speed and changing direction.

Instead of adding 1 to the current speed, you could add abs(speed)/speed so that if speed < 0 then -1 is added and if speed > 0 then +1 is added.

Note: abs(x) = |x|, the absolute value function.

Your programming language should have that intrinsic function.
MarkFL is offline  
February 10th, 2012, 06:10 AM   #3
Joined: Feb 2012

Posts: 2
Thanks: 0

Re: incease speed and changing direction.

it has this Mathf.Abs
didn't think of looking in the mathf functions, grrr stupido!
rottjung is offline  

  My Math Forum > High School Math Forum > Algebra

changing, direction, incease, speed

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the ratio of his usual speed to his speed that day. Chikis Elementary Math 25 January 31st, 2014 08:48 AM
force and direction Melody2 Physics 2 October 28th, 2013 03:44 PM
Need a little direction.... Aimee-D Advanced Statistics 1 July 26th, 2012 04:10 AM
Speed and Direction C42711 Algebra 0 October 30th, 2011 12:06 PM
Jet Speed & Wind Speed RMG46 Algebra 1 July 5th, 2010 09:36 PM

Copyright © 2018 My Math Forum. All rights reserved.