Jump to content

  • Log In with Google      Sign In   
  • Create Account

HELP! Block placing and destroying script doesn't work properly!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Kiel368   Members   -  Reputation: 215

Like
0Likes
Like

Posted 11 November 2012 - 11:53 AM

Hi everyone! I've got a problem. I have voxel game written in Unity. I've got a script attached to my main camera to destroy and place blocks. It works like this:
for (float x = 0; x < 5f; x += 0.05f)
{
Vector3 targetPoint = transform.position + (transform.forward * x);
BlockType blockType = ((World)world.GetComponent(typeof(World))).BlockAtPoint(targetPoint);
if (blockType != BlockType.Air)
{
if (targetPoint.y > 2)
{
Vector2 targetChunkOffset2D = PlayerUtils.GetPlayerPosChunkOffset2D(targetPoint);
Vector3 targetChunkOffset3D = new Vector3(targetChunkOffset2D.x, 0, targetChunkOffset2D.y);
Vector2 targetBlockOffset2D = PlayerUtils.GetRelativeBlockPos(targetChunkOffset3D, targetPoint);
Vector3 targetBlockOffset3D = new Vector3(targetBlockOffset2D.x, targetPoint.y, targetBlockOffset2D.y);
((World)world.GetComponent(typeof(World))).SetBlock(targetChunkOffset3D, targetBlockOffset3D, BlockType.Air);
}
break;
}
}
It works fine but when i have a selector (GUITexture in the middle of the screen) it doesn't fit perfectly. Functions GetPlayerPosChunkOffset2D, GetRelativeBlockPos, BlockAtPoint and SetBlock are written properly.
Please help, this is very important to me!

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS