playMaker

Author Topic: Mathf actions?  (Read 5009 times)

markinjapan

  • Full Member
  • ***
  • Posts: 103
Mathf actions?
« 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



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mathf actions?
« Reply #1 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

bye,

 Jean

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: Mathf actions?
« Reply #2 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?


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mathf actions?
« Reply #3 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

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: Mathf actions?
« Reply #4 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mathf actions?
« Reply #5 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

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: Mathf actions?
« Reply #6 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 :)