Grid floor and walls UNSOLVED! PLEASE HELP

Hello again!



[java]Box box = new Box(new Vector3f(x, y, z), 0.5f, 0.5f, 0.5f);[/java]



The x,y,z is the center of the box you’re creating. When you call:



[java]makeBlock(“Block”,

round(closest.getContactPoint().x),

1,

round(closest.getContactPoint().z))[/java]



I’m assuming this would mean that if you clicked at… Oh I dunno, (0.32, 0, 0.80) then the round method (rounds up?), will make this (1, 0, 1)? I think… anyway. Now, you’re right though, you need to round off somehow, but the problem I’m seeing is what you’re rounding to. You don’t want the center of the new box at (1, 0, 1), you’d want the center of the box to be halfExtents to (0.5, 0, 0.5) I think. That should put the corners all on units of length 1.



If I’m right, I bet you can never get a block to land in the right spot with unit cubes? The reason you could before was because they were 2x2x2 cubes, so occasionally the round up would actually get the center right since the center would indeed be one of the integer values you rounded up to.



I think… XD



~FlaH

1 Like

It works perfectly, but I needed to make some changes, look at the round method:



[java]protected float round(float num)

{

BigDecimal big = new BigDecimal(num);

float result;



big.setScale(1, BigDecimal.ROUND_DOWN);

result = big.intValue();

if(result < 0)

{

result -= 0.5f;

}

else result += 0.5f;



return result;

}[/java]



In the negative part of the floor, I needed to subtract 0.5 else, I would add 05, to make the block get right.

But, I still having some problems when the number is 0… the box is placed wrong.

Sorry for my english :expressionless: