How could I create a ‘snap-to-grid’ effect for added objects (Sims style)?
You could use dLoc to move objects in increments of 1 unit. Or maybe you could use python to do some getPosition, round to nearest 1, setPosition kind of thing. I’ve never tried it before.
The ‘object to be added’ is added on the centre of the ‘object with the actuator’, so you need to make the ‘object with the actuator’ always be snapped to grid. You could try something like this:
x = own.getPosition(0)
y = own.getPosition(1)
z = own.getPosition(2)
own.setPosition([round(x, 0), round(y, 0), round(z, 0)])
This just takes the location of the ‘object with the actuator’ and rounds the x,y and z to 0 decimal points.
Edit, I see that magnum opus has already posted my idea, ohwell.
I can’t believe I didn’t think of rounding setPosition to nearest 1. I shall try that.
Try putting your value into the int() function.
x = own.getPosition(0)
y = own.getPosition(1)
z = own.getPosition(2)
own.setPosition([int(x), int(y), int(z)])
int() turns floats into integers.
Or import python’s math module and use math.ceil()
or math.floor()
import mathx = own.getPosition(0)y = own.getPosition(1)z = own.getPosition(2)own.setPosition([math.ceil(x), math.floor(y), math.ceil(z)])
(floor rounds down and ceil rounds up. I find these methods easer than round() and better for other things.)
look here for my object placement file.
http://www.4shared.com/file/53752276/f2b80653/obj_placement_beta.html
instructions inside.