- Home /
Round x, y and z values of object?
Hey, I'm wanting to have the objects in my scene snap to a grid and so Ive been trying to round the x, y and z values of these objects to the nearest full numbers hoping it would give this effect. My script uses Mathf.round which Ive read does this, however what I have wrote doesn't do anything at all, can someone help me out here?
function Update (){
Mathf.Round(transform.position.x);
Mathf.Round(transform.position.y);
Mathf.Round(transform.position.z);
}
transform.position.x = $$anonymous$$athf.Round(transform.position.x);
etc
Answer by Landern · Aug 15, 2014 at 06:30 PM
Of course not, it DOES do something with the vectors of position, it just doesn't change the value of the vectors in position since the method Mathf.Round is returning a value(the changed value) to nothing.
try:
function Update (){
transform.position.x = Mathf.Round(transform.position.x);
transform.position.y = Mathf.Round(transform.position.y);
transform.position.z = Mathf.Round(transform.position.z);
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Turning Spinners Based on an Integer 0 Answers
Apply low gravity only for specific object. 1 Answer
Rounding to multiples of 0.5 1 Answer
Snap Back? 1 Answer