Example #1
0
        public void PointOnTerrain()
        {
            Ray        ray = Camera.main.ScreenPointToRay(mousePosition);
            RaycastHit hitInfo;

            if (Physics.Raycast(ray, out hitInfo, 250f, ConstraintController.getTerrainMask()))
            {
                points[selectionStage - 1] = hitInfo.point;
                if (hitInfo.point.y > points[0].y)
                { // move first point to new height
                    points[0].y = hitInfo.point.y;
                }
                if (selectionStage > 1)
                { // All points need to be at the same height
                    points[selectionStage - 1].y = points[0].y;
                }

                UpdateSelectionCube(selectionStage);

                //Debug.Log("hitpoint="+hitInfo.point+", TerrainPoistion="+TerrainPosition(hitInfo.point)+" "+PositionTerrain(TerrainPosition(hitInfo.point)));
                testObject.transform.position = hitInfo.point;
                if (selectionStage == 4)
                {
                    insideSelection = isInsideSelection(hitInfo.point);
                }
            }
        }
Example #2
0
        private void MovePlaceableObjectToMouse()
        {
            Ray        ray1 = Camera.main.ScreenPointToRay(mousePosition);
            RaycastHit hitInfo;

            // filter the raycast based on whether this template should be shown on terrain or not
            //LayerMask layerMask = (ConstraintController.ShowOnTerrain(currentBC.template) ? ConstraintController.getTerrainMask() : ConstraintController.getBuildingsMask()) ;
            Vector3 position;

            // 1 - If we hit a building, show the Ghost on it
            if (Physics.Raycast(ray1, out hitInfo, UIController.Instance.forwardOffset, ConstraintController.getBuildingsMask()))
            {
                //Debug.Log("Move to mouse: hit a BUILDING");
                position = ConstraintController.PlaceGhost(currentBC, hitInfo.point, ConstraintController.getBuildingsMask());
            }

            // 2 - If we hit terrain, show the Ghost on it
            else if (Physics.Raycast(ray1, out hitInfo, UIController.Instance.forwardOffset, ConstraintController.getTerrainMask()))
            {
                //Debug.Log("Move to mouse: hit TERRAIN");
                position = ConstraintController.PlaceGhost(currentBC, hitInfo.point, ConstraintController.getTerrainMask());
            }

            // 3 - If we hit nothing, just make the object float in front of us at a distance of forwardOffset
            else
            {
                //Debug.Log("Move to mouse: FLOAT");
                Ray ray2 = Camera.main.ScreenPointToRay(mousePosition);
                position = Camera.main.transform.position + ray2.direction * UIController.Instance.forwardOffset;
            }

            // If I'm in a group, I'm snapped, so only move if I'm a bit far from my current position
            if (currentBC.beyondGroup == null || Vector3.Distance(position, currentBC.transform.position) > groupSnapTolerance)
            {
                currentBC.MoveGhost(position);
            }
            Snap();
        }
Example #3
0
        // Update is called once per frame
        void Update()
        {
            //if (UIController.Instance.gameMode == gameMode.free)
            //{
            timer += Time.deltaTime;
            if (timer > 0.2f)
            {
                // TO DO : Should I check for different masks to prevent jumping from non-jumpable objects ?
                // Does such a thing even exists ?
                isOnGround = Physics.CheckSphere(groundCheck.position, groundDistance, ConstraintController.getTerrainMask()) || Physics.CheckSphere(groundCheck.position, groundDistance, ConstraintController.getBuildingsMask());
                timer      = 0f;
                if (isOnGround && velocity.y < 0)
                {
                    velocity.y = -2f;
                }
            }

            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");

            running = Input.GetKey(KeyCode.LeftShift);

            Vector3 move = transform.right * x + transform.forward * z;

            cc.Move(move * speed * (running ? 2.5f : 1) * Time.deltaTime);

            if (Input.GetButtonDown("Jump") && isOnGround)
            {
                velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            }

            velocity.y += gravity * Time.deltaTime * 5f;
            cc.Move(velocity * Time.deltaTime);
            //}
        }
Example #4
0
 public bool insideTerrain()
 {
     Collider[] collidersHit = Physics.OverlapBox(transform.position, template.castBox, transform.rotation, ConstraintController.getTerrainMask());
     // string debug_string="insideTerrain overlap boxes="; foreach (Collider c in collidersHit) debug_string += c.gameObject.name + ","; Debug.Log(debug_string);
     return(collidersHit.Length > 0);
 }