Ejemplo n.º 1
0
        public virtual void UpdateAnimWhileHolding()
        {
            Ped ped = m_ped;

            ped.PlayerModel.PlayAnim(this.GetAnimBasedOnMovement(this.CanSprintWithIt));
        }
Ejemplo n.º 2
0
 private void Awake()
 {
     m_ped = this.GetComponentInParent <Ped> ();
 }
Ejemplo n.º 3
0
        public virtual void UpdateAnimWhileAiming()
        {
            Ped player        = m_ped;
            var CurrentWeapon = this;
            var PlayerModel   = player.PlayerModel;
            var model         = player.PlayerModel;


            //	this.Play2Animations (new int[]{ 41, 51 }, new int[]{ 2 }, AnimGroup.MyWalkCycle,
            //		AnimGroup.MyWalkCycle, AnimIndex.IdleArmed, AnimIndex.GUN_STAND);

            if (CurrentWeapon.HasFlag(GunFlag.AIMWITHARM))
            {
                // aim with arm
                // eg: pistol, tec9, sawnoff

                model.Play2Anims(new AnimId(AnimGroup.Colt45, AnimIndex.colt45_fire), this.GetAnimBasedOnMovement(false));

                AimAnimState = model.LastAnimState;
                model.LastAnimState.wrapMode = WrapMode.ClampForever;

                model.RemoveAllMixingTransforms(model.LastAnimState);
                model.AddMixingTransform(model.LastAnimState, model.RightClavicle, true);

                model.AddMixingTransform(model.LastSecondaryAnimState, model.LeftClavicle, true);
                model.AddMixingTransforms(model.LastSecondaryAnimState, model.Pelvis, model.Belly, model.Spine, model.UpperSpine, model.RBreast, model.LBreast, model.Neck);

                if (model.AnimsChanged)
                {
                    // reset model state
                    model.ResetModelState();
                    // sample the animation, because otherwise, model will remain in original state for 1 frame
                    model.AnimComponent.Sample();
                }

                this.UpdateFireAnim(model.LastAnimState);


                /*
                 * PlayerModel.PlayAnim (AnimGroup.WalkCycle, AnimIndex.Idle);
                 *
                 * // update fire state
                 *
                 * m_aimAnimTimeForAimWithArmWeapon += Time.deltaTime;
                 *
                 * if (player.WeaponHolder.NumFramesSinceStartedAiming <= 1 || player.WeaponHolder.NumFramesSinceSwitchedWeapon <= 1) {
                 *      m_aimAnimTimeForAimWithArmWeapon = 0f;
                 * }
                 *
                 * if (m_aimAnimTimeForAimWithArmWeapon > this.AimAnimMaxTime) {
                 *
                 *      if (player.WeaponHolder.IsFiring) {
                 *
                 *              // check if anim reached end
                 *              if(m_aimAnimTimeForAimWithArmWeapon >= this.AimAnimFireMaxTime) {
                 *                      // anim reached end, revert it to start
                 *
                 *                      m_aimAnimTimeForAimWithArmWeapon = this.AimAnimMaxTime;
                 *
                 *                      // no longer firing
                 *                      player.WeaponHolder.IsFiring = false;
                 *              }
                 *      } else {
                 *              // check if we should start firing
                 *
                 *              if (player.WeaponHolder.IsFireOn) {
                 *                      // we should start firing
                 *                      player.WeaponHolder.IsFiring = true;
                 *              } else {
                 *                      // we should remain in aim state
                 *                      m_aimAnimTimeForAimWithArmWeapon = this.AimAnimMaxTime;
                 *              }
                 *      }
                 *
                 * }
                 */


                float timePerc = Mathf.Clamp01(model.LastAnimState.time / this.AimAnimMaxTime);

                // rotate arm to match direction of player

                // we'll need a few adjustments, because arm's right vector is player's forward vector,
                // and arm's forward vector is player's down vector => arm's up is player's left
                //	Vector3 forward = - player.transform.right ; // -player.transform.up;
                //	Vector3 up = player.transform.up; // -player.transform.right;
                //	Vector3 lookAtPos = player.transform.position + forward * 500;

                model.ResetFrameState(model.RightUpperArm);
                model.ResetFrameState(model.RightForeArm);
                model.ResetFrameState(model.RightHand);

                Vector3 aimDir      = Camera.main.transform.forward;
                Vector3 aimDirLocal = player.transform.InverseTransformDirection(aimDir);

                bool  isAimingOnOppositeSide = aimDirLocal.x < 0f;
                float oppositeSideAngle      = Vector3.Angle(Vector3.forward, aimDirLocal.WithXAndZ());
                bool  isAimingBack           = oppositeSideAngle > WeaponsManager.Instance.AIMWITHARM_maxAimAngle;

                Quaternion startRot = Quaternion.LookRotation(-player.transform.up, player.transform.forward); // Quaternion.Euler (WeaponsManager.Instance.AIMWITHARM_upperArmStartRotationEulers);
                Quaternion endRot   = Quaternion.LookRotation(aimDir);                                         //Quaternion.LookRotation( forward, up );
                //	Vector3 endForwardLocal = new Vector3(0.9222f, -0.3429f, 0.179f);
                //	Vector3 endUpLocal = new Vector3(-0.3522f, -0.9357f, 0.02171f);
                Quaternion endRotForeArm = endRot;

                if (isAimingBack)
                {
                    // aim in the air

                    endRot = Quaternion.LookRotation(Vector3.Lerp(-player.transform.up, player.transform.forward, 0.7f).normalized);

                    // we need to apply rotation that is opposite of given offset for x axis - to assure that forehand's up matches ped's back
                    Quaternion q = Quaternion.AngleAxis(90f - WeaponsManager.Instance.AIMWITHARM_foreArmRotationOffset.x, player.transform.up);
                    endRotForeArm = Quaternion.LookRotation(q * player.transform.up, q * (-player.transform.forward));
                }
                else if (isAimingOnOppositeSide)
                {
                    // upper arm will slightly follow direction of aiming, but only along y and z axes
                    // forearm will have direction of aiming

                    Vector3 dir = aimDirLocal;
                    dir.x = 0;                     // no looking left or right
                    if (oppositeSideAngle != 0)
                    {
                        //	dir.y = Mathf.Sign (dir.y) * ( Mathf.Abs (dir.y) - 1.0f * oppositeSideAngle / 90f );
                        dir.y -= 1.0f * oppositeSideAngle / 90f;
                        dir.z += 1.0f * oppositeSideAngle / 90f;
                        if (dir.y > 0)
                        {
                            dir.y /= (1.0f + oppositeSideAngle / 90f);
                        }
                        //	if (Mathf.Abs(dir.y) > dir.z)
                        //		dir.z = Mathf.Abs(dir.y);
                    }
                    dir.Normalize();
                    dir    = player.transform.TransformDirection(dir);
                    endRot = Quaternion.LookRotation(dir);
                }

                // lerp
                Quaternion rot        = Quaternion.Lerp(startRot, endRot, timePerc);
                Quaternion rotForeArm = Quaternion.Lerp(startRot, endRotForeArm, timePerc);

                if (timePerc == 1.0f)
                {
                    //	Vector3 localForward = player.transform.InverseTransformDirection (model.RightUpperArm.forward);
                    //	Vector3 localUp = player.transform.InverseTransformDirection (model.RightUpperArm.up);
                    //	Debug.LogFormat ("local forward {0}, local up {1}", localForward.ToString("G4"), localUp.ToString("G4"));
                }

                //	Quaternion deltaRot = Quaternion.FromToRotation (Vector3.forward, aimDirLocal);

                //	Quaternion worldRot = player.transform.TransformRotation( rot );

                //	worldRot *= deltaRot;

                // assign new rotation
                // 'rot' is in player space
                //	model.RightUpperArm.rotation = worldRot;

                //	Quaternion convertRot = Quaternion.Euler (WeaponsManager.Instance.AIMWITHARM_upperArmEndRotationEulers);

                // head rotation
                Vector3    clampedAimDir = F.ClampDirection(aimDir, player.transform.forward, WeaponsManager.Instance.AIMWITHARM_maxHeadRotationAngle);
                Quaternion headRot       = isAimingBack ? player.transform.rotation : Quaternion.LookRotation(clampedAimDir);
                //	headRot = Quaternion.Lerp( model.Head.rotation, headRot, 0.3f);


                // set new rotations and apply aim rotation offsets

                model.Head.rotation = headRot;
                model.Head.Rotate(WeaponsManager.Instance.AIMWITHARM_headRotationOffset);

                model.RightClavicle.Rotate(WeaponsManager.Instance.AIMWITHARM_clavicleRotationOffset);

                model.RightUpperArm.rotation = rot;
                model.RightUpperArm.Rotate(WeaponsManager.Instance.AIMWITHARM_upperArmRotationOffset);

                model.RightForeArm.rotation = rotForeArm;
                model.RightForeArm.Rotate(WeaponsManager.Instance.AIMWITHARM_foreArmRotationOffset);

                model.RightHand.localRotation = Quaternion.identity;
                model.RightHand.Rotate(WeaponsManager.Instance.AIMWITHARM_handRotationOffset);
            }
            else
            {
                //	PlayerModel.PlayUpperLayerAnimations (AnimGroup.Rifle, AnimGroup.WalkCycle, AnimIndex.RIFLE_fire, AnimIndex.Idle);

                AnimationState state = null;

                if (player.IsRunning && player.Movement.sqrMagnitude > float.Epsilon)
                {
                    // walk and aim at the same time

                    float angle = Vector3.Angle(player.Movement, player.transform.forward);

                    if (angle > 110)
                    {
                        // move backward
                        PlayerModel.Play2Anims(this.AimAnim, new AnimId(AnimGroup.Gun, AnimIndex.GunMove_BWD));
                    }
                    else if (angle > 70)
                    {
                        // strafe - move left/right
                        float rightAngle = Vector3.Angle(player.Movement, player.transform.right);
                        if (rightAngle > 90)
                        {
                            // left
                            PlayerModel.Play2Anims(this.AimAnim, new AnimId(AnimGroup.Gun, AnimIndex.GunMove_L));
                        }
                        else
                        {
                            // right
                            PlayerModel.Play2Anims(this.AimAnim, new AnimId(AnimGroup.Gun, AnimIndex.GunMove_R));
                        }

                        // we have to reset local position of root frame - for some reason, anim is changing position
                        //	PlayerModel.RootFrame.transform.localPosition = Vector3.zero;
                        Importing.Conversion.Animation.RemovePositionCurves(PlayerModel.LastSecondaryAnimState.clip, PlayerModel.Frames);

                        PlayerModel.VelocityAxis = 0;
                    }
                    else
                    {
                        // move forward
                        PlayerModel.Play2Anims(this.AimAnim, new AnimId(AnimGroup.Gun, AnimIndex.GunMove_FWD));
                    }

                    PlayerModel.LastAnimState.wrapMode = WrapMode.ClampForever;
                    state = PlayerModel.LastAnimState;
                }
                else
                {
                    // just aim

                    //state = PlayerModel.PlayAnim (this.AimAnim, true, false);
                    PlayerModel.Play2Anims(this.AimAnim, this.AimAnimLowerPart);

                    // some anims don't set root frame velocity, so we have to set it
                    PlayerModel.RootFrame.LocalVelocity = Vector3.zero;

                    state          = PlayerModel.LastAnimState;
                    state.wrapMode = WrapMode.ClampForever;
                }

                AimAnimState = state;


                this.UpdateFireAnim(state);
            }
        }
Ejemplo n.º 4
0
        public static PedStalker SpawnPedStalker(int pedId, Transform nearbyTransform, Ped targetPed)
        {
            Vector3    pos;
            Quaternion rot;

            if (GetPositionForPedSpawn(out pos, out rot, nearbyTransform))
            {
                return(SpawnPedStalker(pedId, pos, rot, targetPed));
            }
            return(null);
        }
Ejemplo n.º 5
0
        public static PedStalker SpawnPedStalker(int pedId, Vector3 pos, Quaternion rot, Ped targetPed)
        {
            var ped = SpawnPed(pedId, pos, rot, true);

            var stalker = ped.gameObject.GetOrAddComponent <PedStalker> ();

            stalker.stoppingDistance = PedManager.Instance.AIStoppingDistance;
            stalker.TargetPed        = targetPed;

            return(stalker);
        }
 private void Awake()
 {
     m_ped = GetComponent <Ped>();
 }
Ejemplo n.º 7
0
        public virtual bool TryFire()
        {
            Ped ped = m_ped;

            if (ped.IsFiring)
            {
                return(false);
            }

            // check if there is ammo in clip
            if (this.AmmoInClip < 1)
            {
                return(false);
            }

            ped.IsFiring = true;

            // reduce ammo
            this.AmmoInClip--;

            // update gun flash
            //	this.EnableOrDisableGunFlash (ped);
            if (this.GunFlash != null)
            {
                this.GunFlash.gameObject.SetActive(true);
            }
            this.UpdateGunFlashRotation();

            // fire projectile
            F.RunExceptionSafe(() => this.FireProjectile());

            // play firing sound
            F.RunExceptionSafe(() => {
                if (m_audioSource && m_audioSource.clip)
                {
                    if (!m_audioSource.isPlaying)
                    {
//						int bankIndex = weaponSoundIndexes [this.Definition.Id];

//						Audio.AudioManager.SfxGENRL137Timings [bankIndex];

//						int startTimeMs = 0;
//						int endTimeMs = 0;
//
//						float startTime = startTimeMs / 1000f;
//						float endTime = endTimeMs / 1000f;

//						Debug.LogFormat("playing weapon sound, start time {0}, end time {1}, bank index {2}", startTime, endTime, bankIndex);

//						m_audioSource.Stop();
//						m_audioSource.time = startTime;
//						m_audioSource.Play();
//						m_audioSource.SetScheduledEndTime( AudioSettings.dspTime + (endTime - startTime) );

                        //	Debug.LogFormat("playing weapon sound");
                        m_audioSource.Stop();
                        m_audioSource.time = 0f;
                        m_audioSource.Play();
                    }
                }
            });


            return(true);
        }