Precise taco
This commit is contained in:
parent
b6de0b08c1
commit
a63568a6ff
@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76087783dd84b37478e6ad0446da7f2c
|
||||
folderAsset: yes
|
||||
timeCreated: 1520975305
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -39,7 +39,8 @@ public class BikeManager : MonoBehaviour {
|
||||
void Start () {
|
||||
distanceToRun = gm.GetRaceDistance();
|
||||
|
||||
taco = gameObject.AddComponent<RAWTachometer>();
|
||||
//taco = gameObject.AddComponent<RAWTachometer>();
|
||||
taco = gameObject.AddComponent<PreciseTachometer>();
|
||||
taco.SetPlayer(playerID);
|
||||
|
||||
normalSpeed = distanceToRun / gm.GetRaceNormalTime();
|
||||
|
25
Assets/Scripts/GameScene/PreciseTachometer.cs
Normal file
25
Assets/Scripts/GameScene/PreciseTachometer.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
13
Assets/Scripts/GameScene/PreciseTachometer.cs.meta
Normal file
13
Assets/Scripts/GameScene/PreciseTachometer.cs.meta
Normal 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:
|
Loading…
Reference in New Issue
Block a user