SOLVED: Scaling int to float

Started by Slasher, Thu 21/02/2019 08:18:16

Previous topic - Next topic

Slasher

Hi

I have a  player which is a little to big for the scene so I manually scaled him down to scale with a boat.

However, the boat walks walkable scaling 70/50.

So I did this:

Code: ags


function repeatedly_execute_always() {
 cTurner.Scaling=cSpeedBoat.Scaling/2;
 }
}


Is there a way to turn this into a float like /2.2?

Cheers ;)

Gilbert

Since Character.Scaling is an int property, you cannot do floating point math directly.
But you can do either:
Code: ags

function repeatedly_execute_always() {
 cTurner.Scaling=(cSpeedBoat.Scaling*50)/70; //Remember the multiplication MUST be done before the division.
 }

or alternatively:
Code: ags

function repeatedly_execute_always() {
 cTurner.Scaling=Maths.FloatToInt(Maths.IntToFloat(cSpeedBoat.Scaling)/1.4, eRoundNearest);
 }

The results of the two methods should be more or less the same, save for some rounding differences.

(Note: This was written when your post wasn't edited yet, hence the 1.4 and not 2.2 .)

Slasher

#2
Thanks Gilbert  (nod)

SMF spam blocked by CleanTalk