public void CheckCollision() { //For checking the player's future 'XYZ' positions float x = worldpos.x + (Collider.size.x * (int)Mathf.Sign(vecloicty.x)); float y = worldpos.y + (Collider.size.y * (int)Mathf.Sign(vecloicty.y)); float z = worldpos.z + (Collider.size.z * (int)Mathf.Sign(vecloicty.z)); Vector3 futurepos = new Vector3(x, y, z); Vector3Int futrgridpos = grid.GetObjectPositionToGrid(futurepos); Vector3Int worlgridpos = grid.GetObjectPositionToGrid(worldpos); if (futrgridpos.x >= 0 && futrgridpos.x < grid.worldsize.x - 1) { if (grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z] != null && grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z].solid) { vecloicty.x = 0; } } else { vecloicty.x = 0; } if (futrgridpos.y >= 0 && futrgridpos.y < grid.worldsize.y - 1) { if (grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z] != null && grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z].solid) { vecloicty.y = 0; } } else { vecloicty.y = 0; } if (grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z] != null && grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z].solid) { worldpos.z = (int)((worldpos.z / 10)) * 10; // This is so that the player lands perfectly on to the block. isgrounded = true; vecloicty.z = 0; } else { isgrounded = false; } }
public void UpdateMouseInput() { Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int mousepogrid = Grid.GetObjectPositionToGrid(mousepos); cursor.transform.position = new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength + z * Grid.GetNodeLength); if (Input.GetKeyDown(KeyCode.A) && Input.GetKeyDown(KeyCode.Space)) { m_position += "\n" + "mpos: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " in area " + levels[currentLevNum].name; } if (Input.GetKeyDown(KeyCode.B) && Input.GetKeyDown(KeyCode.Space)) { m_position = string.Empty; } if (Grid.GetObjectFromGrid(new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength, z * Grid.GetNodeLength))) { txt.text = "Space + A to memorise position \n" + "Space + B to delete position \n" + "Position: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " Focusing on: " + Grid.GetObjectFromGrid(new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength, z * Grid.GetNodeLength)) + " " + m_position; } else { txt.text = "Space + A to memorise position \n" + "Space + B to delete position \n" + "Position: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " " + m_position; } switch (TOOLKIT) { case TOOLKT.BRUSH: text.text = "Brush: " + currentblock.name; if (Input.GetMouseButton(0)) { Grid.SpawnObject(currentblock.name, new Vector3(mousepos.x, mousepos.y, z * Grid.GetNodeLength)); } if (Input.GetMouseButton(1)) { Grid.DespawnObject(new Vector3(mousepos.x, mousepos.y, z * Grid.GetNodeLength)); } break; } }