Example #1
0
    void setAnimState(WeaponPosition wp, bool instantRotate = false)
    {
        if (instantRotate)
        {
            angle       = wp.zRot + Random.Range(-wp.zAngleVariance / 2f, wp.zAngleVariance / 2f);
            TargetAngle = angle;
        }
        else
        {
            TargetAngle = wp.zRot + Random.Range(-wp.zAngleVariance / 2f, wp.zAngleVariance / 2f);
        }
        if (wp.TimeToReachRotation != 0f)
        {
            m_trueRotationSpeed = (TargetAngle - angle) / wp.TimeToReachRotation;
        }
        else
        {
            m_trueRotationSpeed = RotationSpeed;
        }
        float xScale = wp.scale.x + Random.Range(-wp.scaleVariance.x / 2f, wp.scaleVariance.x / 2f);
        float yScale = wp.scale.y + Random.Range(-wp.scaleVariance.y / 2f, wp.scaleVariance.y / 2f);

        transform.localScale = new Vector3(xScale, yScale, 1f);
        sprite_angle         = wp.xRot;
        m_animator.speed     = wp.AnimSpeed;
        m_currentWeaponPos   = wp;
        //Debug.Log("Setting Angle: " + wp.zRot + " to: " + angle);
    }
Example #2
0
 public void StartSlashFX(WeaponPosition wp)
 {
     m_animator.Play("normal", -1, sAngle);
     m_timeStopSlash = Time.timeSinceLevelLoad + wp.timeInPosition;
     m_slashing      = true;
     m_weaponFX      = wp.Animation;
     setAnimState(wp, true);
     //Debug.Log ("Anim Speed: " + wp.AnimSpeed);
 }
        protected override void CalculateTransforms(float distance)
        {
            ProfilerShort.Begin("MyCharacter.CalculateTransforms");

            base.CalculateTransforms(distance);
            if (m_headBoneIndex >= 0 && AnimationController.CharacterBones != null && (IsInFirstPersonView || ForceFirstPersonCamera) && ControllerInfo.IsLocallyControlled() && !IsBot)
            {
                Vector3 headHorizontalTranslation = AnimationController.CharacterBones[m_headBoneIndex].AbsoluteTransform.Translation;
                headHorizontalTranslation.Y = 0;
                MyCharacterBone.TranslateAllBones(AnimationController.CharacterBones, -headHorizontalTranslation);
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Calculate Hand IK");


            if (this == MySession.Static.ControlledEntity)
            {
                // (OM) Note: only controlled character can get it's aimed point from camera, otherwise all character's will aim the same direction
                // set the aimed point explicitly using AimedPoint property
                m_aimedPoint = GetAimedPointFromCamera();
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Update anim IK");

            AnimationController.UpdateInverseKinematics(); // since we already have absolute transforms

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("UpdateLeftHandItemPosition");
            if (m_leftHandItem != null)
            {
                UpdateLeftHandItemPosition();
            }

            if (m_currentWeapon != null && WeaponPosition != null && m_handItemDefinition != null)
            {
                WeaponPosition.Update();
                //mainly IK and some zoom + ironsight stuff
                if (m_handItemDefinition.SimulateLeftHand && m_leftHandIKStartBone != -1 && m_leftHandIKEndBone != -1)
                {
                    MatrixD leftHand = (MatrixD)m_handItemDefinition.LeftHand * ((MyEntity)m_currentWeapon).WorldMatrix;
                    CalculateHandIK(m_leftHandIKStartBone, m_leftForearmBone, m_leftHandIKEndBone, ref leftHand);
                }

                if (m_handItemDefinition.SimulateRightHand && m_rightHandIKStartBone != -1 && m_rightHandIKEndBone != -1 && IsSitting == false)
                {
                    MatrixD rightHand = (MatrixD)m_handItemDefinition.RightHand * ((MyEntity)m_currentWeapon).WorldMatrix;
                    CalculateHandIK(m_rightHandIKStartBone, m_rightForearmBone, m_rightHandIKEndBone, ref rightHand);
                }
            }

            MyRenderProxy.GetRenderProfiler().StartNextBlock("UpdateTransformations");

            AnimationController.UpdateTransformations();

            MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            ProfilerShort.End();
        }
Example #4
0
 public void EquipWeapon(BaseWeapon weapon, WeaponPosition position = WeaponPosition.RIGHT)
 {
     if (position == WeaponPosition.RIGHT)
     {
         this.rightGun = weapon;
     }
     else
     {
         this.leftGun = weapon;
     }
 }
Example #5
0
    private void ActivateHalberd()
    {
        GameObject     h  = GetComponent <HalberdTargetFinder> ().m_halberd;
        WeaponPosition wp = new WeaponPosition();

        wp.timeInPosition = m_clingInfo.BufferFlyTime;
        wp.Animation      = "Normal";
        wp.pos            = m_clingInfo.ClingPosition - transform.position;
        wp.pos            = new Vector2(Mathf.Abs(wp.pos.x), wp.pos.y);
        wp.zRot           = Mathf.Rad2Deg * Mathf.Atan2(m_clingInfo.ClingPosition.y - transform.position.y, Mathf.Abs(m_clingInfo.ClingPosition.x - transform.position.x));
        wp.zRot          += m_clingInfo.HalberdAngleOff;
        wp.zAngleVariance = 0f;
        h.GetComponent <WeaponFloating> ().StartSlashFX(wp);
    }
Example #6
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (Status == Conditions.Shelling && Target != null && TargetDistanceSquared <= RangeSquared)
            {
                var t = (float)((gameTime.TotalGameTime - LastCooldown - Cooldown).TotalSeconds / ShellingDuration.TotalSeconds);
                if (t > 1)
                {
                    t = 1;
                }

                var source = Owner.Position + WeaponPosition.Rotate(MathHelper.PiOver2 + Owner.Angle);
                var target = Target.Position + TargetVarriation;

                var spos = Vector2.Lerp(source, target, t);
                var tpso = spos.Transform(target.Angle(source), 10);//(target - source)/10+target;//spos.Transform(FireAngle , 15);

                spriteBatch.DrawLine(spos + GameControl.Hud.Camera, tpso + GameControl.Hud.Camera,
                                     new Color(Owner.Fraction.Color.R, Owner.Fraction.Color.G, Owner.Fraction.Color.B,
                                               1f//(float)Math.Sin(t*MathHelper.TwoPi*3)
                                               ), DrawOrder.Bullet);
            }

            if (Status == Conditions.CoolingDown && OldTarget != null && gameTime.TotalGameTime - LastCooldown < DebrisDuration)
            {
                float t = (float)((gameTime.TotalGameTime - LastCooldown).TotalSeconds / DebrisDuration.TotalSeconds);
                if (t > 1)
                {
                    t = 1;
                }

                var source = Owner.Position + WeaponPosition.Rotate(MathHelper.PiOver2 + Owner.Angle);
                var target = OldTarget.Position + TargetVarriation;

                var spos = Vector2.Lerp(source, target, 1 + (t) / 5);
                //var spos = Vector2.Lerp(source, target, 1+(float)(((gameTime.TotalGameTime - LastShoot).TotalSeconds / ShootDuration.TotalSeconds)-1)/10);

                for (int i = 0; i < CountDebris; i++)
                {
                    spriteBatch.DrawRectangle(GameControl.Hud.Camera + spos + TargetVarriation + new Vector2(10, 10) * new Vector2(Random.NextFloat() - 0.5f, Random.NextFloat() - 0.5f), 1, 1,
                                              new Color(Random.NextFloat() * 0.5f + t / 2f, Random.NextFloat() * 0.5f + t / 2f, t, 0.5f)
                                              , DrawOrder.Bullet);
                }
            }

            base.Draw(spriteBatch, gameTime);
        }
Example #7
0
        public void Fire(WeaponPosition weaponPosition = WeaponPosition.Unknown)
        {
            if (weaponPosition == WeaponPosition.Unknown)
            {
                foreach (var weapon in m_allEquipment.Values.Where(equip => equip is Weapon).Cast <Weapon>())
                {
                    weapon.Fire();
                }
            }
            else
            {
                foreach (var infoWithWeapon in m_allEquipment.Where(infoPlusWeaponPair => infoPlusWeaponPair.Key is PlaneWeaponRelativeInfo))
                {
                    PlaneWeaponRelativeInfo weaponRelInfo = (PlaneWeaponRelativeInfo)infoWithWeapon.Key;
                    Weapon weapon = (Weapon)infoWithWeapon.Value;

                    if (weaponRelInfo.WeaponPosition == weaponPosition)
                    {
                        weapon.Fire();
                    }
                }
            }
        }
Example #8
0
    void updateState(WeaponPosition wp)
    {
        if (m_currentWeaponPos == null)
        {
            m_currentWeaponPos = wp;
        }
        if (m_currentWeaponPos != wp)
        {
            setAnimState(wp);
        }
        Vector2 off = wp.pos;

        if (Mathf.Abs(TargetAngle - angle) < Mathf.Abs(Time.deltaTime * m_trueRotationSpeed))
        {
            angle += (TargetAngle - angle);
        }
        else
        {
            angle += Time.deltaTime * m_trueRotationSpeed;
        }
        //angle %= 360;
        float drawAngle = angle;

        if (m_target.GetComponent <PhysicsSS> ().FacingLeft)
        {
            off.x         *= -1f;
            m_sprite.flipX = true;
            drawAngle      = -angle;
        }
        else
        {
            m_sprite.flipX = false;
        }
        m_chase.SetTargetOffset(m_target, off);
        m_chase.Accelerate = wp.accel;
        transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, drawAngle + base_angle));
    }
Example #9
0
    private Transform CreateGunContainer(WeaponPosition position)
    {
        string prefabPath = "Prefabs/Weapons/";
        string objectName = "";

        if (position == WeaponPosition.LEFT)
        {
            prefabPath += "LeftGunContainer";
            objectName  = "LeftGun";
        }
        else
        {
            if (PlaythroughManager.Instance.PlayerInfo.Equipment.CurrentWeaponKit == WeaponKit.DUAL_WIELD)
            {
                prefabPath += "RightGunContainer";
                objectName  = "RightGun";
            }
            else
            {
                prefabPath += "TwoHandedGunContainer";
                objectName  = "RightGun";
            }
        }

        GameObject gunContainerObject = Instantiate(Resources.Load(prefabPath)) as GameObject;

        gunContainerObject.name = objectName;

        Transform gunContainerTransform = gunContainerObject.GetComponent <Transform>();
        Vector3   localPosition         = gunContainerTransform.position;

        gunContainerTransform.parent        = this.GetComponent <Transform>();
        gunContainerTransform.localPosition = localPosition;

        return(gunContainerTransform);
    }
Example #10
0
        protected override void CalculateTransforms(float distance)
        {
            ProfilerShort.Begin("MyCharacter.CalculateTransforms");

            base.CalculateTransforms(distance);
            if (m_headBoneIndex >= 0 && AnimationController.CharacterBones != null && (IsInFirstPersonView || ForceFirstPersonCamera) && ControllerInfo.IsLocallyControlled() && !IsBot)
            {
                Vector3 headHorizontalTranslation = AnimationController.CharacterBones[m_headBoneIndex].AbsoluteTransform.Translation;
                headHorizontalTranslation.Y = 0;
                MyCharacterBone.TranslateAllBones(AnimationController.CharacterBones, -headHorizontalTranslation);
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Calculate Hand IK");


            if (this == MySession.Static.ControlledEntity)
            {
                // (OM) Note: only controlled character can get it's aimed point from camera, otherwise all character's will aim the same direction
                // set the aimed point explicitly using AimedPoint property
                m_aimedPoint = GetAimedPointFromCamera();
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Update anim IK");

            AnimationController.UpdateInverseKinematics(); // since we already have absolute transforms

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("UpdateLeftHandItemPosition");
            if (m_leftHandItem != null)
            {
                UpdateLeftHandItemPosition();
            }

            if (m_currentWeapon != null && WeaponPosition != null)
            {
                if (!MyPerGameSettings.CheckUseAnimationInsteadOfIK(m_currentWeapon))
                {
                    WeaponPosition.Update();
                    //mainly IK and some zoom + ironsight stuff
                    if (m_handItemDefinition.SimulateLeftHand && m_leftHandIKStartBone != -1 && m_leftHandIKEndBone != -1 && (!UseAnimationForWeapon))
                    {
                        MatrixD leftHand = (MatrixD)m_handItemDefinition.LeftHand * ((MyEntity)m_currentWeapon).WorldMatrix;
                        CalculateHandIK(m_leftHandIKStartBone, m_leftForearmBone, m_leftHandIKEndBone, ref leftHand);
                    }

                    if (m_handItemDefinition.SimulateRightHand && m_rightHandIKStartBone != -1 && m_rightHandIKEndBone != -1 && (!UseAnimationForWeapon) && IsSitting == false)
                    {
                        MatrixD rightHand = (MatrixD)m_handItemDefinition.RightHand * ((MyEntity)m_currentWeapon).WorldMatrix;
                        CalculateHandIK(m_rightHandIKStartBone, m_rightForearmBone, m_rightHandIKEndBone, ref rightHand);
                    }
                }
                else
                {
                    GetHeadMatrix(true); // CH: REMOVE ME! I'M A TERRIBLE HACK!
                    Debug.Assert(m_rightHandItemBone != -1, "Invalid bone for weapon.");
                    if (m_rightHandItemBone != -1)
                    {
                        //use animation for right hand item
                        MyCharacterBone boneRightHand = AnimationController.CharacterBones[m_rightHandItemBone];
                        ((MyEntity)m_currentWeapon).PositionComp.WorldMatrix = boneRightHand.AbsoluteTransform * PositionComp.WorldMatrix;

                        if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
                        {
                            MyRenderProxy.DebugDrawAxis(((MyEntity)m_currentWeapon).PositionComp.WorldMatrix, 0.5f, false);
                        }
                    }
                }
            }
            else
            {
                if (WeaponPosition != null)
                {
                    WeaponPosition.UpdateIkTransitions();
                }
                GetHeadMatrix(true); // CH: REMOVE ME! I'M A TERRIBLE HACK!
            }


            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("ComputeBoneTransform");

            var characterBones = AnimationController.CharacterBones;

            if (characterBones == null)
            {
                return;
            }
            for (int i = 0; i < characterBones.Length; i++)
            {
                MyCharacterBone bone = characterBones[i];
                bone.ComputeBoneTransform();
                BoneRelativeTransforms[i] = bone.RelativeTransform;
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            ProfilerShort.End();
        }