Example #1
0
    private void UpdateAsPlayer(Entity entity, ref ActorInput actorInput)
    {
        if (!EntityManager.HasComponent(entity, typeof(ActorPlayer)))
        {
            return;
        }


        //Get Player Input
        {
            //AXIS
            actorInput.movement.x = GInput.GetAxisRaw(GAxis.LEFTHORIZONTAL);
            actorInput.movement.z = GInput.GetAxisRaw(GAxis.LEFTVERTICAL);

            //Reset
            actorInput.actionToDo = 0;

            //BUTTONS
            if (GInput.GetButtonDown(GButton.RIGHT))
            {
                actorInput.actionToDo = 1;
            }
            if (GInput.GetButtonDown(GButton.BOTTOM))
            {
                actorInput.actionToDo = 2;
            }
            if (GInput.GetButtonDown(GButton.LEFT))
            {
                actorInput.actionToDo = 3;
            }
            if (GInput.GetButtonDown(GButton.L3))
            {
                actorInput.crouch = (byte)(actorInput.crouch == 1 ? 0 : 1);
            }
            actorInput.sprint = (byte)(GInput.GetButton(GButton.TOP) ? 1 : 0);
            actorInput.strafe = (byte)(GInput.GetButton(GButton.L2) ? 1 : 0);
        }

        //Convert Actor Movement to Camera
        {
            var cameraForward = (Camera.main.transform.TransformDirection(Vector3.forward).normalized);
            cameraForward.y = 0;
            var camreaRight = new Vector3(cameraForward.z, 0, -cameraForward.x);
            actorInput.movement = actorInput.movement.x * camreaRight + actorInput.movement.z * cameraForward;
            actorInput.movement.Normalize();
        }
    }
Example #2
0
    void Update()
    {
        // accumulate the rotation angle
        valueLookX += GInput.GetAxis("Mouse X") * multLookX;
        valueLookY += -GInput.GetAxis("Mouse Y") * multLookY;

        // apply angles
        bodyRigidbodyRotation.eulerAngles        = new Vector3(0f, valueLookX, 0f);
        bodyRigidbody.transform.rotation         = bodyRigidbodyRotation;
        cameraGameObjectRotation.eulerAngles     = new Vector3(valueLookY, 0f, 0f);
        cameraGameObject.transform.localRotation = cameraGameObjectRotation;

        // apply forces
        bodyRigidbody.AddForce(bodyRigidbody.transform.forward * GInput.GetAxis("Vertical") * walkForce + bodyRigidbody.transform.right * GInput.GetAxis("Horizontal") * walkForce);
        if (GInput.GetButton("Jump"))
        {
            bodyRigidbody.AddForce(jumpForce * Vector3.up);
        }
    }