Round TouchY to nearest 50

mikelowemikelowe Member Posts: 177
edited November -1 in Working with GS (Mac)
how do I round my touch.y to the nearest 50. I think I use floor somehow. Please help me.

Comments

  • RHRH Member Posts: 1,079
    If you do (floor(touch.y/50))*50 that will round it down to the nearest multiple

    If you replace floor with ceil that will round it up to the nearest multiple of 50.

    If you put it in a rule that says if touch.y % 50 (you'll need to create a new attribute and calculate that) is greater than 25

    change attribute to (ceil(touch.y/50))*50

    OTHERWISE

    change attribute to (floor(touch.y/50))*50

    I think that should work, haven't tried it and it's early here so forgive me if it doesn't!
  • mikelowemikelowe Member Posts: 177
    thanks so much RH! I'm going to try this right now. I'll let you know if it works.
  • mikelowemikelowe Member Posts: 177
    alright, at first it didn't work.... But I made things a little different in order to get it working.

    I wanted to spawn an actor at a position to the nearest multiple of 50 so that they snap to a grid. I was trying to spawn the actor at a rounded touch point, which wasn't working. I ended up just spawning the actor at the unrounded touch point and then inside the actor's attribute editor, rounding position.x and position.y.

    Your math was correct RH, thank you.
Sign In or Register to comment.