Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: markinjapan on August 07, 2012, 09:13:58 AM

Title: Mathf actions?
Post by: markinjapan on August 07, 2012, 09:13:58 AM
If possible :)

I'm trying to to do this:

http://answers.unity3d.com/questions/210125/rounding-to-multiples-of-05.html

But can't figure out a way to do it with the current actions.

Seems like there are some useful functions in this list:

http://docs.unity3d.com/Documentation/ScriptReference/Mathf.html

I found an 'Float Round' action which has been very useful so far.

Thanks


Title: Re: Mathf actions?
Post by: jeanfabre on August 07, 2012, 09:29:32 AM
Hi,

 not sure what you mean by "I found a float round action", I could not find one in the forum nor the official actions

so I made one:

http://hutonggames.com/playmakerforum/index.php?topic=2073.0 (http://hutonggames.com/playmakerforum/index.php?topic=2073.0)

bye,

 Jean
Title: Re: Mathf actions?
Post by: markinjapan on August 07, 2012, 04:49:38 PM
Sorry, got it wrong way around.

http://hutonggames.com/playmakerforum/index.php?topic=2073.0

Just saying that that one was useful and it's just a small part of the mathf functions.

But, what I'm after specifically is an action that rounds a float to the nearest 0.5 (or any input value).

So, if float = 1.2 then it rounds to 1.0, if 2.8 then it rounds to 3.0, etc.

I think it's called Mathf.Floor?

Title: Re: Mathf actions?
Post by: jeanfabre on August 08, 2012, 05:07:12 AM
Hi,

 This is exactly what round is doing, so the action I created will work for your case.

 1.9 would be 1 if you used floor. 1.1 would be 2 if you used ceil

bye,

 Jean
Title: Re: Mathf actions?
Post by: markinjapan on August 08, 2012, 02:13:32 PM
Ah, I was using a different action. I've just downloaded your action but I can't see how to convert a float (say 1.65) to the closest 0.5 (would be 1.5).

Also, I can't see any option for floor or ceil.

Sorry if I'm missing something.

Thanks
Title: Re: Mathf actions?
Post by: jeanfabre on August 09, 2012, 05:05:11 AM
Hi,

 There is not such math function to round to 1.5 rounding always returns an int. to achieve this, multiply by 2 your value, round them, and then divide by two,

1.65*2 = 3.3
round(3.3) = 3
3/2 = 1.5

1.8*2 = 3.6
round(3.6) = 4
4/2 = 2


 As for floor and ceiling. I'll see if I can do them in the next few days.



bye,

 Jean
Title: Re: Mathf actions?
Post by: markinjapan on August 10, 2012, 05:40:34 AM
[palmsface]

Why didn't I think about that. :s

Adds a few extra steps but that's fine for now.

Thanks :)