generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to invert with math

Previous Thread :: Next Thread 
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
27 Sep 2013 05:37 AM
if eject.Velocity.X > 0 then
NEWVELX = ("-"..eject.Velocity.X) -- This works
elseif eject.Velocity.X ~= 0 then
NEWVELX = (eject.Velocity.X) --I want to invert this
else
NEWVELX = 0
end

Well, the I want to invert eject.Velocity.X, so if it's a negative number then it will go positive. It's to balance out the forces on something for an ejection seat, if you really want to know.

Help appreciated, thanks.

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
27 Sep 2013 05:58 AM
Bumpin'it k.

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
getkoed is not online. getkoed
Joined: 18 Feb 2010
Total Posts: 2298
27 Sep 2013 07:04 AM
if eject.Velocity.X > 0 then
NEWVELX = "-" .. tostring(eject.Velocity.X)
elseif eject.Velocity.X < 0 then
local velx = tostring(eject.Velocity.X)
NEWVELX = tonumber(velx:sub(2, velx:len()))
elseif eject.Velocity.X == 0 then
NEWVELX = 0
end

Probably works, not sure, didn't test it
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
27 Sep 2013 07:25 AM
Uh..inversion is easy....
local x = 1
x = x*-1
print(x)

> -1
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
27 Sep 2013 09:09 AM
Dragon, I can do that. I can go from positive to negative. But I want to go from negative to positive.

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
noah is not online. noah
Joined: 11 Sep 2006
Total Posts: 18977
27 Sep 2013 09:16 AM
print(math.abs(-1))
1
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
27 Sep 2013 09:19 AM
But multiplying it by a -1 will always give you the opposite (as a negative multiplied by a negative is a positive)

iirc, math.abs returns the absolute value (which won't go from positive to negative)

print((-1)*-1) --> 1
print((1)*-1) --> -1
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
27 Sep 2013 09:41 AM
Thanks getkoed, I made it slightly different :)

local velx = tostring(eject.Velocity.X*10) -- Done to increase deceleration
if eject.Velocity.X > 0 then
NEWVELX = "-"..velx
elseif eject.Velocity.X < 0 then
NEWVELX = tonumber(velx:sub(2, velx:len())) -- That's your bit
elseif eject.Velocity.X == 0 then
NEWVELX = 0
end
local velz = tostring(eject.Velocity.Z*10) -- Done to increase deceleration
if eject.Velocity.Z > 0 then
NEWVELZ = "-"..velz
elseif eject.Velocity.Z < 0 then
NEWVELZ = tonumber(velz:sub(2, velz:len())) -- That's your bit
elseif eject.Velocity.Z == 0 then
NEWVELZ = 0
end

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
kubuto2 is not online. kubuto2
Joined: 16 Jul 2008
Total Posts: 1275
27 Sep 2013 11:56 AM
local velx = eject.Velocity.X*10
if eject.Velocity.X > 0 then
NEWVELX = -(velx) -- This switches the number from positive to negative
elseif eject.Velocity.X < 0 then

--NEWVELX = tonumber(velx:sub(2, velx:len())) -- Can you try and explain this line better?

else -- don't need elseif because the other 2 check if it is greater or less
NEWVELX = 0
end

local velz = eject.Velocity.Z*10 -- Done to increase deceleration
if eject.Velocity.Z > 0 then
NEWVELZ = -(velz) -- This switches the number from positive to negative
elseif eject.Velocity.Z < 0 then

--NEWVELZ = tonumber(velz:sub(2, velz:len())) -- Can you try and explain this line better?

else
NEWVELZ = 0
end
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
27 Sep 2013 02:05 PM
I might actually use lupine's or noah's. Thanks guys :)

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image