Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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