Division help (Fracunits are hell)

The21zonz

Just a dude with curly hair
I'm trying to make an spin ability where the amount of momentum a character is thrust forward scales with speed, and I can't figure out how to get the speed you're moving as a percentage (e.g. if top speed is 36 and you're moving at 18 then the output would be be 50%) without running in to evil floating point numbers.

Is this even possible, or am I looking at this the wrong way?
 
I'm trying to make an spin ability where the amount of momentum a character is thrust forward scales with speed, and I can't figure out how to get the speed you're moving as a percentage (e.g. if top speed is 36 and you're moving at 18 then the output would be be 50%) without running in to evil floating point numbers.

Is this even possible, or am I looking at this the wrong way?
The math.floor() function rounds variables down to the closest whole number. I think that’s what you’re looking for?

Though, I thought all SRB2 variables were integers to begin with so I don’t know how you’re running into “evil floating point numbers”. (Which itself is a vague term I don’t think I understand.)
 
Yep. I could make that work! Thank you.
Post automatically merged:

The math.floor() function rounds variables down to the closest whole number. I think that’s what you’re looking for?

Though, I thought all SRB2 variables were integers to begin with so I don’t know how you’re running into “evil floating point numbers”. (Which itself is a vague term I don’t think I understand.)
Edit:

1. That fuction doesn't exist in SRB2 Lua, I don't think.

2. If I try to divide integers, I may end up with floating points; 18*FRACUNITS / 36*FRACUNITS gives you 0.5, and the game can't handle those if I'm not mistaken.
 
Last edited:
1. That fuction doesn't exist in SRB2 Lua, I don't think.
What makes you say that?
The only scenario I see it being omitted in is one where floating points aren't a thing in SRB2. (Which I'm pretty sure is the case as I was trying to say earlier.)

2. If I try to divide integers, I may end up with floating points; 18*FRACUNITS / 36*FRACUNITS gives you 0.5, and the game can't handle those if I'm not mistaken.
May? You haven't tested it yet? I would test it before trying to avoid something that might not even be a problem. :worry:
Again, I'm pretty sure the game doesn't utilize floating points at all. I remember doing division for an SRB2Kart mod and it gave me a whole number, much like the floor function.
 
Huh. I’ll go test that. :sadthumbsup:
Post automatically merged:

I remember doing division for an SRB2Kart mod and it gave me a whole number, much like the floor function.
Edit: GUESS WHAT! FLOORING IS BUILT IN! (i’m an idiot :dramahog:)
 
Last edited:

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top