Esempio n. 1
0
                public void Update()
                {
                    this.lastPos = this.pos;
                    this.pos    += this.vel;
                    this.vel    *= 0.8f;
                    if ((float)this.index == 0f)
                    {
                        this.pos = this.arm.BasePos(1f);
                    }
                    else if (this.index < this.arm.joints.Length - 1)
                    {
                        if (this.index == 1 && (this.arm.baseMoving || this.arm.oracle.room.GetTile(this.previous.ElbowPos(1f, this.pos)).Solid))
                        {
                            Vector2 vector = Custom.InverseKinematic(this.previous.pos, this.next.pos, this.previous.totalLength, this.totalLength, this.currentInvKinFlip);
                            Vector2 from   = Custom.InverseKinematic(this.previous.pos, this.next.pos, this.previous.totalLength, this.totalLength, -this.currentInvKinFlip);
                            float   num    = (!this.arm.oracle.room.GetTile(vector).Solid) ? 0f : 10f;
                            num += ((!this.arm.oracle.room.GetTile(this.previous.ElbowPos(1f, Vector2.Lerp(vector, this.previous.pos, 0.2f))).Solid) ? 0f : 1f);
                            float num2 = (!this.arm.oracle.room.GetTile(from).Solid) ? 0f : 10f;
                            num2 += ((!this.arm.oracle.room.GetTile(this.previous.ElbowPos(1f, Vector2.Lerp(from, this.previous.pos, 0.2f))).Solid) ? 0f : 1f);
                            if (num > num2)
                            {
                                this.currentInvKinFlip *= -1f;
                                vector = Custom.InverseKinematic(this.previous.pos, this.next.pos, this.previous.totalLength, this.totalLength, this.currentInvKinFlip);
                            }
                            else if (num == 0f)
                            {
                                this.vel += Vector2.ClampMagnitude(vector - this.pos, 100f) / 100f * 1.8f;
                            }
                        }
                        SharedPhysics.TerrainCollisionData terrainCollisionData = new SharedPhysics.TerrainCollisionData(this.pos, this.lastPos, this.vel, 1f, new IntVector2(0, 0), true);
                        terrainCollisionData = SharedPhysics.VerticalCollision(this.arm.oracle.room, terrainCollisionData);
                        terrainCollisionData = SharedPhysics.HorizontalCollision(this.arm.oracle.room, terrainCollisionData);
                        terrainCollisionData = SharedPhysics.SlopesVertically(this.arm.oracle.room, terrainCollisionData);
                        this.pos             = terrainCollisionData.pos;
                        this.vel             = terrainCollisionData.vel;
                    }
                    if (this.next != null)
                    {
                        Vector2 vector2 = Custom.DirVec(this.pos, this.next.pos);
                        float   num3    = Vector2.Distance(this.pos, this.next.pos);
                        float   num4    = 0.5f;
                        if (this.index == 0)
                        {
                            num4 = 0f;
                        }
                        else if (this.index == this.arm.joints.Length - 2)
                        {
                            num4 = 1f;
                        }
                        float num5 = -1f;
                        float num6 = 0.5f;
                        if (this.previous != null)
                        {
                            Vector2 lhs = Custom.DirVec(this.previous.pos, this.pos);
                            num6 = Custom.LerpMap(Vector2.Dot(lhs, vector2), -1f, 1f, 1f, 0.2f);
                        }
                        if (num3 > this.totalLength)
                        {
                            num5 = this.totalLength;
                        }
                        else if (num3 < this.totalLength * num6)
                        {
                            num5 = this.totalLength * num6;
                        }
                        if (num5 > 0f)
                        {
                            this.pos      += vector2 * (num3 - num5) * num4;
                            this.vel      += vector2 * (num3 - num5) * num4;
                            this.next.vel -= vector2 * (num3 - num5) * (1f - num4);
                        }
                    }
                    else
                    {
                        Vector2 a = this.arm.oracle.bodyChunks[1].pos;

                        a -= this.arm.oracle.oracleBehavior.GetToDir * this.totalLength / 2f;

                        a        += Custom.DirVec(this.arm.oracle.bodyChunks[1].pos, this.pos) * this.totalLength / 2f;
                        this.vel += Vector2.ClampMagnitude(a - this.pos, 50f) / 50f * 1.2f;
                        this.pos += Vector2.ClampMagnitude(a - this.pos, 50f) / 50f * 1.2f;
                        Vector2 a2   = Custom.DirVec(this.pos, this.arm.oracle.bodyChunks[0].pos);
                        float   num7 = Vector2.Distance(this.pos, this.arm.oracle.bodyChunks[0].pos);
                        this.pos += a2 * (num7 - this.totalLength);
                        this.vel += a2 * (num7 - this.totalLength);
                    }
                }
Esempio n. 2
0
        public override void Update(bool eu)
        {
            base.Update(eu);

            switch (base.mode)
            {
            case Mode.Free:
                if (spinning)
                {
                    if (Custom.DistLess(base.firstChunk.pos, base.firstChunk.lastPos, 4f * room.gravity))
                    {
                        stillCounter++;
                    }
                    else
                    {
                        stillCounter = 0;
                    }
                    if (base.firstChunk.ContactPoint.y < -10.0f || stillCounter > 20)
                    {
                        spinning             = false;
                        rotationSpeed        = 0f;
                        rotation             = Custom.DegToVec(Mathf.Lerp(-90, 90f, Random.value) + 180f);
                        base.firstChunk.vel *= 0f;
                        room.PlaySound(SoundID.Spear_Stick_In_Ground, base.firstChunk);
                    }
                }
                else if (!Custom.DistLess(base.firstChunk.lastPos, base.firstChunk.pos, 6f))
                {
                    SetRandomSpin();
                }
                break;

            case Mode.Thrown:
                SetRandomSpin();
                soundLoop.sound  = SoundID.Spear_Spinning_Through_Air_LOOP;
                soundLoop.Volume = Mathf.InverseLerp(5f, 15f, base.firstChunk.vel.magnitude);
                break;
            }
            for (int i = 0; i < strap.GetLength(0); i++)
            {
                float t = (float)i / (float)(strap.GetLength(0) - 1);
                strap[i, 1]  = strap[i, 0];
                strap[i, 0] += strap[i, 2];
                strap[i, 2] -= rotation * Mathf.InverseLerp(1f, 0f, i) * 0.8f;
                strap[i, 4]  = strap[i, 3];
                strap[i, 3]  = (strap[i, 3] + strap[i, 5] * Custom.LerpMap(Vector2.Distance(strap[i, 0], strap[i, 1]), 1f, 18f, 0.05f, 0.3f)).normalized;
                strap[i, 5]  = (strap[i, 5] + Custom.RNV() * UnityEngine.Random.value * Mathf.Pow(Mathf.InverseLerp(1f, 18f, Vector2.Distance(strap[i, 0], strap[i, 1])), 0.3f)).normalized;
                if (room.PointSubmerged(strap[i, 0]))
                {
                    strap[i, 2]   *= Custom.LerpMap(strap[i, 2].magnitude, 1f, 10f, 1f, 0.5f, Mathf.Lerp(1.4f, 0.4f, t));
                    strap[i, 2].y += 0.05f;
                    strap[i, 2]   += Custom.RNV() * 0.1f;
                    continue;
                }
                strap[i, 2]   *= Custom.LerpMap(Vector2.Distance(strap[i, 0], strap[i, 1]), 1f, 6f, 0.999f, 0.7f, Mathf.Lerp(1.5f, 0.5f, t));
                strap[i, 2].y -= room.gravity * Custom.LerpMap(Vector2.Distance(strap[i, 0], strap[i, 1]), 1f, 6f, 0.6f, 0f);
                if (i % 3 == 2 || i == strap.GetLength(0) - 1)
                {
                    SharedPhysics.TerrainCollisionData cd = new SharedPhysics.TerrainCollisionData(strap[i, 0], strap[i, 1], strap[i, 2], 1f, new IntVector2(0, 0), goThroughFloors: false);
                    cd          = SharedPhysics.HorizontalCollision(room, cd);
                    cd          = SharedPhysics.VerticalCollision(room, cd);
                    cd          = SharedPhysics.SlopesVertically(room, cd);
                    strap[i, 0] = cd.pos;
                    strap[i, 2] = cd.vel;
                    if (cd.contactPoint.x != 0)
                    {
                        strap[i, 2].y *= 0.6f;
                    }
                    if (cd.contactPoint.y != 0)
                    {
                        strap[i, 2].x *= 0.6f;
                    }
                }
            }
            for (int j = 0; j < strap.GetLength(0); j++)
            {
                if (j > 0)
                {
                    Vector2 normalized = (strap[j, 0] - strap[j - 1, 0]).normalized;
                    float   num        = Vector2.Distance(strap[j, 0], strap[j - 1, 0]);
                    float   d          = ((!(num > conRad)) ? 0.25f : 0.5f);
                    strap[j, 0]     += normalized * (conRad - num) * d;
                    strap[j, 2]     += normalized * (conRad - num) * d;
                    strap[j - 1, 0] -= normalized * (conRad - num) * d;
                    strap[j - 1, 2] -= normalized * (conRad - num) * d;
                    if (j > 1)
                    {
                        normalized       = (strap[j, 0] - strap[j - 2, 0]).normalized;
                        strap[j, 2]     += normalized * 0.2f;
                        strap[j - 2, 2] -= normalized * 0.2f;
                    }
                    if (j < strap.GetLength(0) - 1)
                    {
                        strap[j, 3] = Vector3.Slerp(strap[j, 3], (strap[j - 1, 3] * 2f + strap[j + 1, 3]) / 3f, 0.1f);
                        strap[j, 5] = Vector3.Slerp(strap[j, 5], (strap[j - 1, 5] * 2f + strap[j + 1, 5]) / 3f, Custom.LerpMap(Vector2.Distance(strap[j, 1], strap[j, 0]), 1f, 8f, 0.05f, 0.5f));
                    }
                }
                else
                {
                    strap[j, 0]  = StrapAttachPos(1f);
                    strap[j, 2] *= 0f;
                }
            }
        }
 // Token: 0x060021A9 RID: 8617 RVA: 0x001FC424 File Offset: 0x001FA624
 public void Update()
 {
     lastPos = pos;
     pos    += vel;
     vel    *= 0.8f;
     if ((float)index == 0f)
     {
         pos = arm.BasePos(1f);
     }
     else if (index < arm.joints.Length - 1)
     {
         if (index == 1 && (arm.baseMoving || arm.oracle.room.GetTile(previous.ElbowPos(1f, pos)).Solid))
         {
             Vector2 vector = Custom.InverseKinematic(previous.pos, next.pos, previous.totalLength, totalLength, currentInvKinFlip);
             Vector2 from   = Custom.InverseKinematic(previous.pos, next.pos, previous.totalLength, totalLength, -currentInvKinFlip);
             float   num    = (!arm.oracle.room.GetTile(vector).Solid) ? 0f : 10f;
             num += ((!arm.oracle.room.GetTile(previous.ElbowPos(1f, Vector2.Lerp(vector, previous.pos, 0.2f))).Solid) ? 0f : 1f);
             float num2 = (!arm.oracle.room.GetTile(from).Solid) ? 0f : 10f;
             num2 += ((!arm.oracle.room.GetTile(previous.ElbowPos(1f, Vector2.Lerp(from, previous.pos, 0.2f))).Solid) ? 0f : 1f);
             if (num > num2)
             {
                 currentInvKinFlip *= -1f;
                 vector             = Custom.InverseKinematic(previous.pos, next.pos, previous.totalLength, totalLength, currentInvKinFlip);
             }
             else if (num == 0f)
             {
                 vel += Vector2.ClampMagnitude(vector - pos, 100f) / 100f * 1.8f;
             }
         }
         SharedPhysics.TerrainCollisionData terrainCollisionData = new SharedPhysics.TerrainCollisionData(pos, lastPos, vel, 1f, new IntVector2(0, 0), true);
         terrainCollisionData = SharedPhysics.VerticalCollision(arm.oracle.room, terrainCollisionData);
         terrainCollisionData = SharedPhysics.HorizontalCollision(arm.oracle.room, terrainCollisionData);
         terrainCollisionData = SharedPhysics.SlopesVertically(arm.oracle.room, terrainCollisionData);
         pos = terrainCollisionData.pos;
         vel = terrainCollisionData.vel;
     }
     if (next != null)
     {
         Vector2 vector2 = Custom.DirVec(pos, next.pos);
         float   num3    = Vector2.Distance(pos, next.pos);
         float   num4    = 0.5f;
         if (index == 0)
         {
             num4 = 0f;
         }
         else if (index == arm.joints.Length - 2)
         {
             num4 = 1f;
         }
         float num5 = -1f;
         float num6 = 0.5f;
         if (previous != null)
         {
             Vector2 lhs = Custom.DirVec(previous.pos, pos);
             num6 = Custom.LerpMap(Vector2.Dot(lhs, vector2), -1f, 1f, 1f, 0.2f);
         }
         if (num3 > totalLength)
         {
             num5 = totalLength;
         }
         else if (num3 < totalLength * num6)
         {
             num5 = totalLength * num6;
         }
         if (num5 > 0f)
         {
             pos      += vector2 * (num3 - num5) * num4;
             vel      += vector2 * (num3 - num5) * num4;
             next.vel -= vector2 * (num3 - num5) * (1f - num4);
         }
     }
     else
     {
         Vector2 a = arm.oracle.bodyChunks[1].pos;
         //if (this.arm.oracle.ID == Oracle.OracleID.SS)
         //{
         a -= arm.oracle.oracleBehavior.GetToDir * totalLength / 2f;
         //}
         //else
         //{
         //    a -= Custom.PerpendicularVector(this.arm.oracle.oracleBehavior.GetToDir) * this.totalLength / 2f;
         //}
         a   += Custom.DirVec(arm.oracle.bodyChunks[1].pos, pos) * totalLength / 2f;
         vel += Vector2.ClampMagnitude(a - pos, 50f) / 50f * 1.2f;
         pos += Vector2.ClampMagnitude(a - pos, 50f) / 50f * 1.2f;
         Vector2 a2   = Custom.DirVec(pos, arm.oracle.bodyChunks[0].pos);
         float   num7 = Vector2.Distance(pos, arm.oracle.bodyChunks[0].pos);
         pos += a2 * (num7 - totalLength);
         vel += a2 * (num7 - totalLength);
     }
 }