Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (firstFrame) {
            firstFrame = false;
            go = GameObject.FindGameObjectWithTag ("Ball");
            co = go.GetComponent<SphereCollider> ();
            rb = go.GetComponent<Rigidbody> ();
            startPosition = go.transform.position;

            goDog = GameObject.FindGameObjectWithTag("dog");
            lookatIK = goDog.GetComponent<LookAtIK>();
            lookatIK.enabled = true;
        }

        lookatIK.solver.IKPosition = go.transform.position;

        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit hit;
        bool ret = co.Raycast (ray, out hit, 100.0f) && Input.GetMouseButton(0);

        switch(state)
        {
        case State.None:
            if(ret)
            {
                state = State.Grasp;
                go.transform.position = PetHelper.ProjectPointLine(go.transform.position, ray.GetPoint(0), ray.GetPoint(100.0f));
                lastPosition = Input.mousePosition;
            }
            break;
        case State.Grasp:
            if(Input.GetMouseButton(0))
            {
                go.transform.position = PetHelper.ProjectPointLine(go.transform.position, ray.GetPoint(0), ray.GetPoint(100.0f));
                lastPosition = Input.mousePosition;
            }
            else
            {
                Vector3 curPosition = Input.mousePosition;
                Vector3 delta = curPosition - lastPosition;
                float forceLen = delta.magnitude / Time.deltaTime * forceMultiplier;
                if(forceLen < forceThreshold)
                {
                    state = State.None;
                    go.transform.position = startPosition;
                }
                else
                {
                    Vector3 force = (delta.x * (Quaternion.Inverse(Camera.main.transform.rotation) * (new Vector3(1, 0, 0))) + delta.y * (Quaternion.Inverse(Camera.main.transform.rotation) * forceOrient)).normalized * forceLen;
                    rb.isKinematic = false;
                    rb.AddForce(force);
                    this.gameObject.GetComponent<BallCamera>().enabled = true;
                    this.gameObject.GetComponent<BallDogController>().enabled = true;
                    this.enabled = false;
                }
            }
            break;
        }
    }
Example #2
0
    public void Initialize()
    {
        this.MyAnimator = GetComponentInChildren<Animator>();
        this.MyReference = GetComponentInChildren<CharacterReference>();
        this.MyEventHandler = GetComponentInChildren<CharacterEventHandler>();

        this.MyReference.ParentCharacter = this;

        //setup animator parameters initial values
        this.MyAnimator.SetBool("IsAiming", false);
        this.MyAnimator.SetBool("IsSneaking", false);

        this.Destination = transform.position;
        MyNavAgent = GetComponent<NavMeshAgent>();
        UpperBodyState = HumanUpperBodyStates.Idle;
        ActionState = HumanActionStates.None;

        //load aim target and look target
        GameObject aimTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKAimTargetRoot"));
        GameObject lookTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKLookTarget"));
        AimTargetRoot = aimTarget.transform;
        AimTarget = AimTargetRoot.Find("IKAimTarget").transform;
        LookTarget = lookTarget.transform;

        this.MyAimIK = GetComponentInChildren<AimIK>();
        this.MyAimIK.solver.target = AimTarget;
        this.MyAimIK.solver.IKPositionWeight = 0;
        this.MyAimIK.solver.SmoothDisable();

        this.MyLeftHandIK = GetComponentInChildren<LeftHandIKControl>();
        this.MyLeftHandIK.Initialize();

        this.MyHeadIK = GetComponentInChildren<LookAtIK>();
        this.MyHeadIK.solver.target = LookTarget;

        this.MyStatus = new CharacterStatus();
        this.MyStatus.Initialize();

        //each time a human char is initialized it's added to NPC manager's list of human characters to keep track of
        GameManager.Inst.NPCManager.AddHumanCharacter(this);

        CurrentAnimState = new HumanAnimStateIdle(this);
        //SendCommand(HumanCharCommands.Unarm);

        MyAI = GetComponent<AI>();
        MyAI.Initialize(this);

        //subscribe events
        this.MyEventHandler.OnLongGunPullOutFinish += OnLongGunPullOutFinish;
        this.MyEventHandler.OnLongGunPutAwayFinish += OnLongGunPutAwayFinish;
        this.MyEventHandler.OnPistolPullOutFinish += OnPistolPullOutFinish;
        this.MyEventHandler.OnPistolPutAwayFinish += OnPistolPutAwayFinish;
        this.MyEventHandler.OnReloadFinish += OnReloadFinish;
        this.MyEventHandler.OnThrowFinish += OnThrowFinish;
        this.MyEventHandler.OnThrowLeaveHand += OnThrowLeaveHand;
        this.MyEventHandler.OnBulletInjury += OnBulletInjury;
        this.MyEventHandler.OnDeath += OnDeath;
    }
Example #3
0
        private float weight;         // Current weight

        void Awake()
        {
            // Find the components
            interactionSystem = GetComponent <InteractionSystem>();
            lookAt            = GetComponent <LookAtIK>();

            // Add to the interaction system delegates
            interactionSystem.OnInteractionStart += OnInteractionStart;
        }
Example #4
0
        private float weight; // Current weight

        #endregion Fields

        #region Methods

        void Awake()
        {
            // Find the components
            interactionSystem = GetComponent<InteractionSystem>();
            lookAt = GetComponent<LookAtIK>();

            // Add to the interaction system delegates
            interactionSystem.OnInteractionStart += OnInteractionStart;
        }
Example #5
0
    // Use this for initialization
    void Start()
    {
        goDog = GameObject.FindGameObjectWithTag ("dog");
        goBall = GameObject.FindGameObjectWithTag ("Ball");
        goMouth = GameObject.FindGameObjectWithTag ("Mouth");
        lookatIK = goDog.GetComponent<LookAtIK> ();

        state = State.Look;
        lookatIK.enabled = true;
        Vector3 bodyToMouth = goMouth.transform.position - goDog.transform.position;
        bodyToMouth.y = 0.0f;
        mouthDistance = bodyToMouth.magnitude;
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        GameObject goDog = GameObject.FindGameObjectWithTag ("dog");
        lookatIK = goDog.GetComponent<LookAtIK> ();
        goDog.GetComponent<DogController> ().EnableLookatIK (true);
        lookatIK.solver.IKPosition = Camera.main.transform.position;

        lookatBodyWeight = lookatIK.solver.bodyWeight;
        lookatHeadWeight = lookatIK.solver.headWeight;
        lookatEyeWeight = lookatIK.solver.eyesWeight;
        lookatIK.solver.bodyWeight = 0;
        lookatIK.solver.headWeight = 0;
        lookatIK.solver.eyesWeight = 0;
        velBody = 0;
        velHead = 0;
        velEye = 0;
    }
Example #7
0
 // Use this for initialization
 void Start()
 {
     GameObject goDog = GameObject.FindGameObjectWithTag ("dog");
     lookatIK = goDog.GetComponent<LookAtIK> ();
     lookatIK.enabled = true;
 }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        if (firstFrame) {
            firstFrame = false;
            go = GameObject.FindGameObjectWithTag ("Ball");
            co = go.GetComponent<SphereCollider> ();
            rb = go.GetComponent<Rigidbody> ();
            startPosition = go.transform.position;
            screenz = Camera.main.WorldToScreenPoint(go.transform.position).z;

            goDog = GameObject.FindGameObjectWithTag("dog");
            lookatIK = goDog.GetComponent<LookAtIK>();
            goDog.GetComponent<DogController>().EnableLookatIK(true);
        }

        lookatIK.solver.IKPosition = go.transform.position;

        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit hit;
        bool ret = co.Raycast (ray, out hit, 100.0f) && Input.GetMouseButton(0);

        switch(state)
        {
        case State.None:
            if(ret)
            {
                state = State.Grasp;
                go.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenz));
                lastPosition = go.transform.position;
            }
            break;
        case State.Grasp:
            if(Input.GetMouseButton(0))
            {
                go.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenz));
                lastPosition = go.transform.position;
            }
            else
            {
                Vector3 curPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenz));
                Vector3 force = curPosition - lastPosition;
                force += Camera.main.transform.rotation * (new Vector3(0,0,force.magnitude));
                force /= Time.deltaTime;
                force *= forceMultiplier;
                if(force.magnitude < forceThreshold)
                {
                    state = State.None;
                    go.transform.position = startPosition;
                }
                else
                {
                    rb.isKinematic = false;
                    rb.AddForce(force);
                    this.gameObject.GetComponent<BallCamera>().enabled = true;
                    this.gameObject.GetComponent<BallDogController>().enabled = true;
                    this.enabled = false;
                }
            }
            break;
        }
    }