Sign in to follow this  

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

This topic is 1893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
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!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By loyalsheep
      Hey guys!
      Check out the trailer of Airavat. It's a minimalist, space survival game (and hard, very hard) 
      Download on GooglePlay: Airavat
    • By anomalystudiospt
      Hey, we are new around here!
      Our team spent the last year developing a prototype game called Rise of The Fey, a game that focuses on a dramatic story with a fast paced gameplay.
      Rise of The Fey is a third-person action-adventure RPG set within a fantasy world called Perrah. In Rise you control Kall, a young spaunian looking for revenge after the death of his beloved.

      We would appreciate if you could take a look at our stuff, tell us what you think and possibly help us out on Indiegogo.
      The prototype is in portuguese, sorry about that!
      Have a good one!
    • By juglar
      Hi guys, we are developing a game called BiteOff! based on Zombies topic. BiteOff! is based on a game strategy mechanics, free to play, where the player has a bunch of zombies and he can distribute them along the map landscape to be able to bite and transform all humans into each level. Humans are controlled by artificial intelligence and they differ each other on capabilities based on different weapons that give them three different levels of aggressiveness to defend against the zombies. The zombies are also presented in three types and they are differentiated by their attack, speed, strength and resistance abilities. Through different achievements, (time to eat all humans, score, among others) the player can access four extra skills that can enhance your attack in real time on next levels as power-ups.
      We are launching a crowdfunding campaign in kickico and we need some helps please visit us on the crowdfunding page 
      Twitter @biteoffthegame
    • By Lord McMutton
      The world of Ethios is held aloft by massive trees known as the Pillars.
  • Popular Now