Precise taco

This commit is contained in:
Florent Guiotte 2018-03-15 07:05:47 +01:00
parent b6de0b08c1
commit a63568a6ff
4 changed files with 40 additions and 11 deletions

View File

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: 76087783dd84b37478e6ad0446da7f2c
folderAsset: yes
timeCreated: 1520975305
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -39,7 +39,8 @@ public class BikeManager : MonoBehaviour {
void Start () { void Start () {
distanceToRun = gm.GetRaceDistance(); distanceToRun = gm.GetRaceDistance();
taco = gameObject.AddComponent<RAWTachometer>(); //taco = gameObject.AddComponent<RAWTachometer>();
taco = gameObject.AddComponent<PreciseTachometer>();
taco.SetPlayer(playerID); taco.SetPlayer(playerID);
normalSpeed = distanceToRun / gm.GetRaceNormalTime(); normalSpeed = distanceToRun / gm.GetRaceNormalTime();

View File

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class PreciseTachometer : Tachometer {
public float delta = 1f;
public int sampleCount = 2;
public override float GetSpeed() {
if (impulses.Count < sampleCount)
return 0f;
var samples = impulses.Skip(impulses.Count - sampleCount);
float deltaT = samples.Last() - samples.First();
float deltaT2 = Time.time - samples.Last();
if (deltaT2 > deltaT)
deltaT = deltaT2;
return distancePerTick * (sampleCount - 1) / deltaT;
}
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: bdffdeda5fff446daa9f7200d2c0d343
timeCreated: 1521093088
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: