Пример #1
0
    void SpinnerMove()
    {
        if (Input.GetKey(AttackKey) && Energy > EnergyUse)
        {
            UseEnergy();

            IsOn = true;

            if (SpinnerSpeed < SpinnerMaxSpeed)
            {
                SpinnerSpeed += SpinnerMaxSpeed / 60f;
            }
            else
            {
                SpinnerSpeed = SpinnerMaxSpeed;
            }
        }
        else
        {
            PlusEnergy();
            IsOn = false;
            if (SpinnerSpeed > 0f)
            {
                SpinnerSpeed -= SpinnerMaxSpeed / 60f;
            }
            else
            {
                SpinnerSpeed = 0f;
            }
        }

        Rb.MoveRotation(Quaternion.Euler(Rb.rotation.eulerAngles.x, Rb.rotation.eulerAngles.y + SpinnerSpeed * Time.fixedDeltaTime, Rb.rotation.eulerAngles.z));
    }
Пример #2
0
    public override void CharacterMove(Vector2 movement)
    {
        float moveX = movement.x;
        float moveY = movement.y;

        if (Mathf.Abs(moveX) > 0 && Mathf.Abs(moveY) > 0)
        {
            if (GlobalVariables.IsHorizontalMovingFirst)
            {
                movement = new Vector3(moveX, 0, 0);
            }
            else
            {
                movement = new Vector3(0, moveY, 0);
            }
        }
        else if (Mathf.Abs(moveX) > 0)
        {
            movement = new Vector3(moveX, 0, 0);
        }
        else if (Mathf.Abs(moveY) > 0)
        {
            movement = new Vector3(0, moveY, 0);
        }
        else
        {
            Rb.velocity = Vector3.zero;
            CharacterStateController.SetParams(ISMOVING, false);
            return;
        }

        movement *= BasicMovingSpeed;
        Rb.AddForce(movement);
        CharacterStateController.SetParams(ISMOVING, true);
    }
Пример #3
0
 /// <summary>
 /// Moves to the target aka. the player-base.
 /// </summary>
 private void MoveToTarget()
 {
     if (Math.Abs(Rb.velocity.x) < maxSpeed)
     {
         Rb.AddForce(new Vector2(baseMovementSpeed * Time.fixedDeltaTime * (TargetToLeft ? -1 : 1), 0));
     }
 }
Пример #4
0
    protected new void Awake()
    {
        if (netMass == 0)
        {
            Rb = GetComponentInParent <Rigidbody>();

            if (!Rb)
            {
                Rb = gameObject.AddComponent <Rigidbody>();
                Rb.SetDensity(density);
                netMass = Rb.mass;

                DestroyImmediate(Rb);
                IsStatic = true;
            }
            else
            {
                Rb.SetDensity(density);
            }
        }
        else
        {
            GetComponentInParent <Rigidbody>().SetDensity(density);
        }

        base.Awake();
    }
Пример #5
0
    /*
     * This method is what controls the side sweeping motion
     * While the key is held down, your vehicle banks and moves in
     * that direction.
     * After they are down banking, the vehicle rights itself
     * Speed is a constant associated with a type of vehicle
     * Correction is how much the player wants to move sideways
     * Previous steer what the player inputed last frame.
     * turning makes sure the player is not turning while banking
     *
     */

    protected void MoveHorizontal(float speed, float correction, float previousSteer, bool turning)
    {
        if (StateManager.curState == 3)
        {
            //make sure we only detect landscape
            int layerMask = 1 << 9;
            //left side of vehicle
            RaycastHit lhit;
            //right side of vehicle
            RaycastHit rhit;
            //Getting the ground
            Physics.Raycast(transform.position + 2 * transform.right, Vector3.down, out rhit, Mathf.Infinity, layerMask);
            Physics.Raycast(transform.position + -2 * transform.right, Vector3.down, out lhit, Mathf.Infinity, layerMask);
            //if we turning right
            if (correction > .8 && !turning)
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance * 300, transform.position + -2 * transform.right);
                Rb.AddForce(transform.right * speed * correction * 20);
                //left
            }
            else if (correction < -.8)
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance * 300, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance, transform.position + -2 * transform.right);
                Rb.AddForce(transform.right * speed * correction * 20);
                //must bring balance to the forces
            }
            else
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance * 15, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance * 15, transform.position + -2 * transform.right);
            }
        }
    }
Пример #6
0
    public override void AddForce(Vector3 netForce, Vector3 allomanticForce)
    {
        // Calculate drag from its new velocity
        // Effectively caps the max velocity of the coin without affecting the ANF.
        Vector3 newNetForce = netForce;

        //Vector3 newNetForce = Vector3.ClampMagnitude(
        //    -(Vector3.Project(Rb.velocity, netForce.normalized) + (netForce / NetMass * Time.fixedDeltaTime)) * drag, netForce.magnitude
        //) + netForce;
        if (collisionCollider)                                                           // If in a collision..
        {
            if (isStuck)                                                                 // and is stuck...
            {
                if (!IsStuckByFriction(netForce) && !IsStuckByFriction(allomanticForce)) // ... but friction is too weak to keep the coin stuck in the target.
                                                                                         // Check both netForce and allomanticForce because the APB may decrease
                                                                                         // the netForce, even when the allomanticForce would be good enough for friction
                {
                    UnStick();
                }
            }
            else     // and is not yet stuck from the previous pushes...
            {
                isStuck = IsStuckByFriction(netForce) || IsStuckByFriction(allomanticForce);
                if (isStuck)   // but this push would stick the coin.
                {
                    CreateJoint(collisionCollider.GetComponent <Rigidbody>());
                }
            }
        }
        LastExpectedAcceleration = newNetForce / NetMass; // LastPosition, LastVelocity are updated
        Rb.AddForce(newNetForce * (1 / Time.timeScale));
    }
Пример #7
0
    protected override void OnTriggerEnter(Collider col)
    {
        if (col.CompareTag("LevelEdge"))
        {
            gameObject.SetActive(false);
            ReturnToPool();
            EventManager.TriggerEvent("Damage", null);
        }

        if (col.CompareTag("Stick"))
        {
            if (IsOnStick)
            {
                return;
            }

            _target = col.transform;
            Invoke("NewParent", 0.2f);
            IsOnStick      = true;
            Rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;
            var pointContact = Collider.ClosestPoint(col.transform.position);
            var direction    = col.transform.TransformPoint(col.bounds.size) - col.transform.position;
            direction = new Vector3(direction.x, 0, 0);
            Rb.AddForceAtPosition(direction * PowerInpuls, pointContact, ForceMode.Impulse);
        }
    }
Пример #8
0
    protected override void OnTriggerEnter(Collider col)
    {
        base.OnTriggerEnter(col);

        if (col.CompareTag("Stick"))
        {
            if (IsOnStick)
            {
                return;
            }

            ManagerSound.Instance.PlayEffect(Track.FruitSplash);
            var pointContact = Collider.ClosestPoint(col.transform.position);
            var angelContact = col.GetComponent <DataObject>().RotationZ + 180f;

            var particle = PoolManager.GetObject(PoolType.Particles).GetComponent <ParticleSystem>();
            particle.gameObject.SetTransform(pointContact, Quaternion.Euler(0, 0, angelContact), col.transform);
            particle.GetComponent <ParticleSystemRenderer>().material = ColorParticle.Colors[(int)TypFruit];
            particle.Play();

            IsOnStick      = true;
            Rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY |
                             RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY |
                             RigidbodyConstraints.FreezeRotationX;
            var direction = col.transform.TransformPoint(col.bounds.size) - col.transform.position;
            direction = new Vector3(direction.x, 0, 0);
            Rb.AddForceAtPosition(direction * _powerImpuls, pointContact, ForceMode.Impulse);
            Collider.enabled = false;
        }
    }
Пример #9
0
    private void HandleLoop()
    {
        if (interpolate < 1)
        {
            interpolate = Mathf.Clamp(interpolate + speed * Time.deltaTime, 0, 1);
        }

        if (index != targetPoints.Length - 1)
        {
            Rb.MovePosition(Vector3.Lerp(targetPoints[index].position, targetPoints[index + 1].position, interpolate));
            if (transform.position == targetPoints[index + 1].position)
            {
                index++;
                interpolate = 0;
            }
        }
        else
        {
            Rb.MovePosition(Vector3.Lerp(targetPoints[index].position, targetPoints[0].position, interpolate));
            if (transform.position == targetPoints[0].position)
            {
                index       = 0;
                interpolate = 0;
            }
        }
    }
 private void Jump()
 {
     if (Input.GetKeyDown(jump))
     {
         Rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
     }
 }
Пример #11
0
    public override void AmmoBehaviourFire()
    {
        Rb.AddForce(Direction * Force, ForceMode2D.Impulse);

        // In case of bug
        Destroy(gameObject, 10.0f);
    }
Пример #12
0
    // Use this for initialization
    protected override void Awake()
    {
        base.Awake();

        var hinf = new RaycastHit();

        Grounded = Observable.EveryFixedUpdate()
                   .Select(_ => Physics.Raycast(RaycastOrigin, Vector3.down, out hinf, Level.Instance.DistBetweenAnchors, LayerMask.GetMask("Bounds", "Blocks", "Characters")))
                   .ToReadOnlyReactiveProperty(true);

        Grounded.AddTo(this);

        Grounded.Subscribe(x => Anim.SetBool("Falling", !x));

        ObservableHP = this.ObserveEveryValueChanged(x => x.CurHp)
                       .ToReadOnlyReactiveProperty(CurHp);

        IsDead = ObservableHP
                 .Select(x => x <= 0)
                 .ToReadOnlyReactiveProperty(false);

        Rb.OnCollisionEnterAsObservable()
        .Select(c => c.collider.GetComponentInParent <GameCharacter>())
        .Where(gc => gc && (gc.transform.position - transform.position).y < -Level.Instance.DistBetweenAnchors * .5f)
        .TakeUntil(IsDead.Where(x => x))
        .Subscribe(gc =>
        {
            target.Value = gc;
            gc.GetHit();
            Rb.AddForce(Vector3.up * 3.5f, ForceMode.Impulse);
        })
        .AddTo(this);
    }
Пример #13
0
    public override void OnAttack()
    {
        Debug.Log("ONATTACK");
        if (Vector2.Distance((Vector2)transform.position, centerPoint) > 1 && !onCenterPoint)
        {
            Vector2 dir = (centerPoint - (Vector2)transform.position).normalized;
            Rb.MovePosition((Vector2)transform.position + dir * speed * Time.deltaTime);
        }
        else
        {
            canChangeState        = true;
            changeDirectionTimer += Time.deltaTime;
            onCenterPoint         = true;
            MoveUpDown();
            shootTimer += Time.deltaTime;

            int rand = Random.Range(0, 100);
            if (rand < 30 && shootTimer >= fireRatio)
            {
                Vector2 playerPos = Player.transform.position;
                Shoot((Vector2)transform.position - playerPos);
            }
            else if (rand >= 30 && shootTimer >= fireRatio)
            {
                shootTimer = 0;
            }
        }
    }
Пример #14
0
    protected override IDisposable Die()
    {
        Rb.DOKill();
        Rb.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");

        Anim.SetTrigger("Die");

        if (deathSound)
        {
            SoundController.Play(deathSound.name);
        }

        return(transform.ObserveEveryValueChanged(x => x.position.y)       // если труп куда-то улетел ...
               .AsUnitObservable()
               .SkipUntil(Observable.TimerFrame(2))
               .Delay(TimeSpan.FromSeconds(.5f))
               .Merge(Observable.Timer(TimeSpan.FromSeconds(2)).AsUnitObservable())          //...  или прошло 2 секунды ...
               .Take(1)
               .Subscribe(_ =>
        {
            DOTween.Sequence()
            .Append(GetComponentInChildren <Renderer>()?.material.DOFade(0, 1f))                            //... фейдим материал в 0 и удаляем геймобджект
            .AppendCallback(() => Destroy(gameObject));
        })
               .AddTo(this));
    }
Пример #15
0
    public override void OnIdle()
    {
        //if (!ScreenUtils.IsInside(new Vector2(transform.position.x + size.x, transform.position.y), backgroundBounds))
        if (Vector2.Distance((Vector2)transform.position, centerPoint) > 1 && !onCenterPoint)
        {
            Vector2 dir = (centerPoint - (Vector2)transform.position).normalized;
            Rb.MovePosition((Vector2)transform.position + dir * speed * Time.deltaTime);
        }
        else
        {
            canChangeState        = true;
            changeDirectionTimer += Time.deltaTime;
            onCenterPoint         = true;
            MoveUpDown();
            shootTimer += Time.deltaTime;

            int rand = Random.Range(0, 100);
            if (rand < 30 && shootTimer >= fireRatio)
            {
                Shoot(Vector2.left);
            }
            else if (rand >= 30 && shootTimer >= fireRatio)
            {
                shootTimer = 0;
            }
        }
    }
Пример #16
0
    // ReSharper disable once UnusedMember.Local
    void Move()
    {
        float moveH = 0;

        if (IsGrounded)
        {
            moveH = Input.GetAxis("Horizontal") * Speed * Time.deltaTime;
        }
        float moveV = Input.GetAxis("Vertical") * Speed * Time.deltaTime;

        if (!IsGrounded)
        {
            moveV *= 0.3f;
        }

        if (Input.GetAxis("Vertical") > 0.9)
        {
            moveV *= 1.5f;
        }

        //Debug.Log("MoveH = " + moveH + " moveV = " + moveV);
        Rb.AddForce(transform.right * moveH);
        Rb.AddForce(transform.forward * moveV);


        Animator.SetBool(CharacterAnimatorState.isMoving.ToString(), Math.Abs(moveV) + Math.Abs(moveH) > 0);

        Animator.SetBool(CharacterAnimatorState.isWalkingStraight.ToString(), Input.GetAxis("Vertical") > 0);
        Animator.SetBool(CharacterAnimatorState.isStraffing.ToString(), Math.Abs(Input.GetAxis("Horizontal")) > 0);

        Animator.SetFloat(CharacterAnimatorState.XWalking.ToString(), Input.GetAxis("Vertical"));
        Animator.SetFloat(CharacterAnimatorState.YWalking.ToString(), Input.GetAxis("Horizontal"));
    }
        private void Moving()
        {
            var dir = new Vector3();
            var ws  = Input.GetAxis("Vertical");
            var ad  = Input.GetAxis("Horizontal");

            if (Math.Abs(ws) > 0)
            {
                dir += Cam.forward * ws;
            }
            if (Math.Abs(ad) > 0)
            {
                dir += Cam.right * ad;
            }
            if (Input.GetKey(up))
            {
                dir += Cam.up;
            }
            if (Input.GetKey(down))
            {
                dir -= Cam.up;
            }
            if (Input.GetKey(speedBoost))
            {
                dir *= speedBoostFactor;
            }
            Rb.AddForce(dir * speed, ForceMode.Impulse);
        }
Пример #18
0
 public virtual void StartJump()
 {
     State = GlobalVar.State.Jump;
     xVec  = Rb.velocity.x;
     Rb.AddForce(Vector2.up * GlobalVar.PlayerValue.JumpUpForce);
     OnGround = false;
 }
Пример #19
0
 public virtual void AddForce(Vector3 netForce)
 {
     if (!IsStatic)
     {
         LastExpectedAcceleration = netForce / Mass;
         Rb.AddForce(netForce, ForceMode.Force);
     }
 }
 public void Initialize(float speed, float curving, float?curvingDuration)
 {
     Speed            = speed;
     _curving         = curving;
     _curvingDuration = curvingDuration;
     Rb.AddForce(transform.forward * speed, ForceMode.VelocityChange);
     _initialized = true;
 }
Пример #21
0
 /// <summary>
 /// Convert this color to an hex string with format #AARRGGBB
 /// </summary>
 /// <returns>Hex string.</returns>
 public string ColorToHex()
 {
     return(String.Format("#{0}{1}{2}{3}"
                          , Ab.ToString("X").Length == 1 ? String.Format("0{0}", Ab.ToString("X")) : Ab.ToString("X")
                          , Rb.ToString("X").Length == 1 ? String.Format("0{0}", Rb.ToString("X")) : Rb.ToString("X")
                          , Gb.ToString("X").Length == 1 ? String.Format("0{0}", Gb.ToString("X")) : Gb.ToString("X")
                          , Bb.ToString("X").Length == 1 ? String.Format("0{0}", Bb.ToString("X")) : Bb.ToString("X")));
 }
Пример #22
0
 /// <summary>
 /// Jumps to the closest target
 /// </summary>
 /// <param name="damageable"></param>
 protected override void Attack(Damageable damageable)
 {
     Rb.AddForce(new Vector2(
                     attackJumpForceX.GetRandom() * (EnemyToLeft ? -1 : 1),
                     attackJumpForceY.GetRandom())
                 );
     _canGetRepulsed = true;
 }
Пример #23
0
 public virtual void AddForce(Vector3 netForce, Vector3 allomanticForce /* unused for the Magnetic base class */)
 {
     if (!IsStatic)
     {
         LastExpectedAcceleration = netForce / netMass;
         Rb.AddForce(netForce, ForceMode.Force);
     }
 }
Пример #24
0
 /*
  * This method is what turns the vehicles about the y axis
  * turn is the player input
  * speed is a constant defined for a particular vehicle
  */
 void TurnRotate(float turn, float speed)
 {
     if (StateManager.curState == 3)
     {
         //transform.RotateAround (transform.position, transform.up, turn * speed / 5);
         Rb.AddTorque(inverseTrap * transform.up * turn * speed * 40);
     }
 }
Пример #25
0
        /// <summary>   Dashes. </summary>
        /// <param name="dashDistance"> The dash distance. </param>
        public void Dash(float dashDistance)
        {
            Vector3 dashVelocity = Vector3.Scale(transform.forward,
                                                 dashDistance * new Vector3(Mathf.Log(1f / (Time.deltaTime * Rb.drag + 1)) / -Time.deltaTime, 0,
                                                                            Mathf.Log(1f / (Time.deltaTime * Rb.drag + 1)) / -Time.deltaTime));

            Rb.AddForce(dashVelocity, ForceMode.VelocityChange);
        }
Пример #26
0
    private void Update()
    {
        //Прыжки

        if (Input.GetButtonDown("Jump") && Grounded)
        {
            Rb.AddForce(new Vector2(0.0f, JumpForce), ForceMode2D.Impulse);
        }
    }
Пример #27
0
 private void Move()
 {
     if (newMoveReady)
     {
         Rb.MovePosition(nextPosition);
         transform.rotation = nextRotation;
         newMoveReady       = false;
     }
 }
Пример #28
0
 /// <summary>
 /// Repulses the enemy after the attack
 /// </summary>
 private void GetRepulsed()
 {
     if (!_canGetRepulsed)
     {
         return;
     }
     Rb.AddForce(new Vector2(attackRepulseForce.GetRandom() * (EnemyToLeft ? 1 : -1), 0f));
     _canGetRepulsed = false;
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        // Check Velocity > 0 or DIE
        if (Rb.velocity.sqrMagnitude < float.Epsilon)
        {
            ; // TODO: Player Dies
        }
        // Lean
        var leanH = -MaxLeanForce *MassModifier *Input.GetAxis("Horizontal");

        var leanV = -MaxLeanForce *MassModifier *Input.GetAxis("Vertical");

        if (InvertSideLean)
        {
            leanH *= -1;
        }
        if (InvertFwdLean)
        {
            leanV *= -1;
        }

        var forcePosn = transform.TransformPoint(new Vector3(0, 1, 0));
        var forceDirn = transform.TransformDirection(new Vector3(0, 0, leanH));

        var tilt = Mathf.Acos(Vector3.Dot(transform.TransformDirection(new Vector3(0, 0, 1)), Vector3.up)) - (Mathf.PI / 2.0f);



        if (false && Mathf.Abs(tilt) > (MaxLeanAngle * Mathf.PI / 180))
        {
            Debug.Log("Tilt!!!" + (tilt * 180.0 / Mathf.PI).ToString("N3") + " > " + (MaxLeanAngle * Mathf.PI / 180));
            Rb.AddRelativeTorque(new Vector3(-leanH, 0, leanV), LeanMode); // Lean Left/Right, Forward/Back
        }
        else
        {
            Rb.AddRelativeTorque(new Vector3(leanH, 0, leanV), LeanMode); // Lean Left/Right, Forward/Back
        }
        Rb.AddRelativeForce(new Vector3(-leanV, 0, leanH));               // Move Left/Right

        if (leanH != 0 || leanV != 0)
        {
            Debug.Log("Lean H: " + leanH.ToString("N3") + " , V: " + leanV.ToString("N3"));
        }



        // Brake

        CurrentBrake = MaxBrakeForce * Input.GetAxis("Brake");

        Rb.drag = Mathf.Max(InitialDrag, CurrentBrake);

        if (CurrentBrake != 0)
        {
            Debug.Log("Brake: " + CurrentBrake.ToString("N3"));
        }
    }
Пример #30
0
        protected override void Move()
        {
            Vector3 targetDir = Lane.Paths[PathIndex].PathPoints[PathPointIndex].Point - transform.position;
            float   step      = Speed * Time.deltaTime;
            Vector3 newDir    = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);

            Rb.MoveRotation(Quaternion.LookRotation(newDir));
            Rb.MovePosition(transform.position + (Target.Point - transform.position).normalized * step);
        }
 /// <summary>
 /// Called when the atmosphere effect is reloaded
 /// </summary>
 private void Effect_OnReload( Rb.Assets.Interfaces.ISource obj )
 {
     m_Techniques = new TechniqueSelector( m_Effect.Asset, m_Techniques.Name );
 }