Ejemplo n.º 1
0
        private void MoveSection()
        {
            if (SECTION_MOVELEFT)
            {
                Vector3 left = TrackDataHelper.SectionGetRotation(TRACK_DATA.SECTIONS[SECTION_CURRENT]) * -Vector3.right;
                TRACK_DATA.SECTIONS[SECTION_CURRENT].SECTION_POSITION += left * Section_MOVEAMOUNT;
                SECTION_MOVELEFT = false;
            }

            if (SECTION_MOVERIGHT)
            {
                Vector3 right = TrackDataHelper.SectionGetRotation(TRACK_DATA.SECTIONS[SECTION_CURRENT]) * Vector3.right;
                TRACK_DATA.SECTIONS[SECTION_CURRENT].SECTION_POSITION += right * Section_MOVEAMOUNT;
                SECTION_MOVERIGHT = false;
            }

            if (SECTION_MOVEFORWARD)
            {
                Vector3 forward = TrackDataHelper.SectionGetRotation(TRACK_DATA.SECTIONS[SECTION_CURRENT]) * Vector3.forward;
                TRACK_DATA.SECTIONS[SECTION_CURRENT].SECTION_POSITION += forward * Section_MOVEAMOUNT;
                SECTION_MOVEFORWARD = false;
            }

            if (SECTION_MOVEBACK)
            {
                Vector3 back = TrackDataHelper.SectionGetRotation(TRACK_DATA.SECTIONS[SECTION_CURRENT]) * Vector3.back;
                TRACK_DATA.SECTIONS[SECTION_CURRENT].SECTION_POSITION += back * Section_MOVEAMOUNT;
                SECTION_MOVEBACK = false;
            }
        }
Ejemplo n.º 2
0
    private void UpdateCurrentSection()
    {
        if (!iSectionFound)
        {
            return;
        }

        // update respawn
        respawnPosition    = r.currentSection.SECTION_NEXT.SECTION_POSITION;
        respawnPosition.y += r.settings.AG_HOVER_HEIGHT;
        respawnRotation    = TrackDataHelper.SectionGetRotation(r.currentSection.SECTION_NEXT);
    }
Ejemplo n.º 3
0
    private void UpdateDirection()
    {
        Vector3 trackRot = TrackDataHelper.SectionGetRotation(r.currentSection) * Vector3.forward;

        float dot = Vector3.Dot(transform.forward, trackRot.normalized);

        if (dot > 0)
        {
            r.facingFoward = true;
        }
        else if (dot < 0)
        {
            r.facingFoward = false;
        }
    }
Ejemplo n.º 4
0
        private void OnDrawGizmos()
        {
            if (TRACK_DATA == null)
            {
                return;
            }

            Vector3 pos        = Vector3.zero;
            Vector3 pos2       = Vector3.zero;
            Color   gizmoColor = Color.white;

            for (int i = 0; i < TRACK_DATA.SECTIONS.Count; i++)
            {
                // get positions to draw line
                pos  = TRACK_DATA.SECTIONS[i].SECTION_POSITION;
                pos2 = pos + TRACK_DATA.SECTIONS[i].SECTION_NORMAL * 1;

                // draw sphere and line
                gizmoColor = Color.white;
                if ((TR_FLAGPAINTER != null && TRACK_DATA.SECTIONS[i] == highlightedSection && PAINT_MODE == E_PAINTMODE.SECTION) ||
                    (EDIT_SECITIONPOSITIONS && i == SECTION_CURRENT))
                {
                    gizmoColor = Color.red;
                }
                Gizmos.color = gizmoColor;
                Gizmos.DrawWireSphere(pos, 0.2f);
                Gizmos.DrawWireSphere(pos2, 0.2f);
                Gizmos.DrawLine(pos, pos2);

                // draw line between sections
                if (i < TRACK_DATA.SECTIONS.Count - 1)
                {
                    pos2 = TRACK_DATA.SECTIONS[i + 1].SECTION_POSITION;
                    Gizmos.DrawLine(pos, pos2);
                }

                // draw orientation
                pos  = pos + TRACK_DATA.SECTIONS[i].SECTION_NORMAL * 0.5f;
                pos2 = pos + (TrackDataHelper.SectionGetRotation(TRACK_DATA.SECTIONS[i]) * Vector3.forward) * 1;
                Gizmos.DrawLine(pos, pos2);
            }
        }
Ejemplo n.º 5
0
        public void FindSpawnTiles()
        {
            // clear any previous spawns
            spawnPositions.Clear();
            spawnRotations.Clear();

            // search through each tile for spawn tiles
            for (int i = 0; i < TRACK_DATA.TILES_FLOOR.Count; i++)
            {
                // if this tile is a spawn tile then add it to the spawn transform arrays
                if (TRACK_DATA.TILES_FLOOR[i].TILE_TYPE == E_TILETYPE.SPAWN)
                {
                    Vector3 spawnPos = TRACK_DATA.TILES_FLOOR[i].TILE_POSITION;
                    spawnPos.y += 0.5f;

                    spawnPositions.Add(spawnPos);
                    spawnRotations.Add(TrackDataHelper.SectionGetRotation(TRACK_DATA.TILES_FLOOR[i].TILE_SECTION));

                    Vector3 cameraPos = TRACK_DATA.TILES_FLOOR[i].TILE_SECTION.SECTION_POSITION;
                    cameraPos.y += 0.5f;
                    spawnCameraLocations.Add(cameraPos);
                }
            }
        }
Ejemplo n.º 6
0
    private void FollowTrack()
    {
        // parent camera
        transform.parent = r.transform;

        // only follow track if current section exist
        if (r.currentSection == null)
        {
            return;
        }

        // position and rotate track helper (this is so we have a transform to work with)
        TrSection current        = r.currentSection;
        Vector3   currentSegment = current.SECTION_POSITION;

        cameraHelper.transform.position = currentSegment;

        Quaternion currentRot = TrackDataHelper.SectionGetRotation(current);

        cameraHelper.transform.rotation = currentRot;

        // figure out the camera's offset to the track
        Vector3 cameraOffset = cameraHelper.transform.InverseTransformPoint(transform.position);

        // figure out which way the ship is facing and interpolate track direction dot product value to it
        Vector3 trackForward = cameraHelper.transform.forward;

        tcDirectionLag = Mathf.Lerp(tcDirectionLag, Vector3.Dot(transform.forward, trackForward), Time.deltaTime * (tcSpeed * 0.5f));

        tcTrackOffset = Vector3.Lerp(tcTrackOffset, cameraOffset * tcDirectionLag, Time.deltaTime * (tcSpeed * 0.65f));
        tcFinalOffset = Vector3.Lerp(tcFinalOffset, cameraOffset, Time.deltaTime * (tcSpeed * 0.65f));

        // figure out which side of the track the camera is on (this is for positioning reasons)
        Vector3 trackSide = cameraHelper.transform.right;
        float   sideDot   = Vector3.Dot(transform.forward, trackSide);
        float   sideFinal = Mathf.Sign(cameraOffset.x) * -Mathf.Sign(sideDot);

        // interpolate positions
        tcX = Mathf.Lerp(tcX, -tcTrackOffset.x * r.settings.CAMERA_OFFSET_SENSITIVITY.x, Time.deltaTime * (r.settings.CAMERA_OFFSET_SPEED.x));
        tcY = Mathf.Lerp(tcY, Mathf.Abs(tcFinalOffset.x) * r.settings.CAMERA_OFFSET_SENSITIVITY.y, Time.deltaTime * (r.settings.CAMERA_OFFSET_SPEED.y * 0.15f));
        tcZ = Mathf.Lerp(tcZ, (Mathf.Abs(cameraOffset.x) * r.settings.CAMERA_OFFSET_SENSITIVITY.z) * (sideFinal * (1 - Mathf.Abs(tcDirectionLag))), Time.deltaTime * (r.settings.CAMERA_OFFSET_SPEED.z * 0.4f));

        // increase/decrease distance to ship on slopes
        float upDir = Vector3.Dot(Vector3.up, r.transform.forward);

        tcPitchOffset = Mathf.Lerp(tcPitchOffset, upDir * 0.2f, Time.deltaTime * tcSpeed);

        // fall Offsets
        if (r.sim.isShipGrounded)
        {
            tcFallTimer     = 0;
            tcFallTimerGain = 0;
        }
        else
        {
            tcFallTimer += Time.deltaTime;
        }

        if (tcFallTimer > 0.2f)
        {
            tcFallTimerGain = Mathf.Lerp(tcFallTimerGain, 0.8f, Time.deltaTime);
            tcFallLagY      = Mathf.Lerp(tcFallLagY, 0.4f, Time.deltaTime * tcFallTimerGain);
            tcFallLagZ      = Mathf.Lerp(tcFallLagZ, -0.8f, Time.deltaTime * (tcFallTimerGain * 4));
        }
        else
        {
            tcFallTimerGain = 0;
            tcFallLagY      = Mathf.Lerp(tcFallLagY, 0.0f, Time.deltaTime * 4);
            tcFallLagZ      = Mathf.Lerp(tcFallLagZ, 0.0f, Time.deltaTime * 4);
        }

        // apply camera offset
        transform.localPosition = new Vector3(r.settings.CAMERA_OFFSET_TRACK.x + tcX, r.settings.CAMERA_OFFSET_TRACK.y + tcY + tcFallLagY, r.settings.CAMERA_OFFSET_TRACK.z + tcZ + tcPitchOffset + tcFallLagZ);

        // update Rotation
        transform.rotation = r.transform.rotation;

        // update FoV
        r.cam.fieldOfView = 75.0f;
    }