Quantcast
Viewing latest article 14
Browse Latest Browse All 115

Minecraft Clone Block Placing Script - need help

hello , im trying to make a minecraft clone and im working on the placing system i made a script it works , when i try to place a block from above a block it works perfectly but when i try to place a block from the side the block is set inside the block i clicked i hit and same happens when i place a block from bellow, if you can help me or give me a working code to base my code on that would be great , thanks for reading. var DistaneFired : int; var ShootFrom : Transform; var CurrentItem : GameObject; function Update () { CurrentItem.SetActive(true); if(Input.GetMouseButtonUp(0)) { var hit : RaycastHit; var Direction : Vector3 = transform.TransformDirection(Vector3.forward); Debug.DrawRay(ShootFrom.position,Direction*DistaneFired,Color.blue); if(Physics.Raycast(ShootFrom.position, Direction,hit,DistaneFired)) { hit.transform.tag="occ_des"; } } if(Input.GetMouseButtonUp(1)) { var use : RaycastHit; var Direction2 : Vector3 = transform.TransformDirection(Vector3.forward); var hitrotatition = Quaternion.FromToRotation(Vector3.up, use.normal); Debug.DrawRay(ShootFrom.position,Direction2*DistaneFired,Color.yellow); if(Physics.Raycast(ShootFrom.position, Direction2,use,DistaneFired)) { if(CurrentItem.name!="pickaxe" && CurrentItem.name!="Sword") { if(use.transform.name!="Collider(Clone)) { print(use.point); use.point.x=Mathf.Round(use.point.x); use.point.z=Mathf.Round(use.point.z); use.point.y+=0.5; print(use.point); Instantiate(CurrentItem, use.point,hitrotatition); } } } } } ps occ_des is the tag i use to destroy blocks, all the problems are at the use part

Viewing latest article 14
Browse Latest Browse All 115

Trending Articles