/// <summary> /// Determines if car should move or not. Moves car if it should /// </summary> private void Update() { // if car is stopped, start stop timer if (m_stopped) { m_stopTimer += Time.deltaTime; if (m_stopTimer >= StopTime) { m_stopped = false; m_stopTimer = 0.0f; } } if (!m_stopped && !m_waiting) { transform.Translate(Vector3.forward * Speed * Time.deltaTime); } // stop car if about to collide with car in same lane if (Physics.Raycast(transform.position + transform.forward + Vector3.up, transform.forward, out RaycastHit hit, m_collider.bounds.size.z + StopDistance)) { if (hit.collider.tag == "Car") { CarActor other = hit.collider.GetComponent <CarActor>(); if (other.Lane == Lane) { m_waiting = true; } } }
public Player(Game game, CarActor carActor, KeyConfig keyboardConfiguration, CameraController cameraController) : base(game) { this.carActor = carActor; this.keyConfig = keyboardConfiguration; this.cameraController = cameraController; }
public CameraController(Game game, CarActor carActor) : base(game) { this.carActor_ = carActor; cameraState_ = new LinkedList <CameraState>(); listener_ = new AudioListener(); SetupCamera(); }
public static void updateStateFromNetwork(this CarActor carActor, PacketReader reader) { // read values and apply to carActor: // position and orientation and velocity carActor.WorldTransform = reader.ReadMatrix(); carActor.LinearVelocity = reader.ReadVector3(); carActor.AngularVelocity = reader.ReadVector3(); }
public static void sendStateToNetwork(this CarActor carActor, PacketWriter writer) { // read values from carActor and send over network: // position, orientation and velocity writer.Write(carActor.WorldTransform); writer.Write(carActor.LinearVelocity); writer.Write(carActor.AngularVelocity); }
public CarSoundManager(CarActor car, CameraController camera, Game game) : base(game) { cueArray = new Cue[CarSoundEmitters.AudioEmitters.Count]; car_ = car; listener_ = camera.Listener; camera_ = camera; state_ = camera.CurrentCamera.State; }
public ParticleController(Game game, CarActor carActor) : base(game) { this.carActor = carActor; particleSystems = new List <ParticleSystem>(); particleSystems.Add(new ParticleSystem(game, game.Content, "Particles/FireSettings")); particleSystems.Add(new ParticleSystem(game, game.Content, "Particles/ProjectileTrailSettings")); fireEmitter = new ParticleEmitter(particleSystems[0], 10f, Vector3.Zero); smokeEmitter = new ParticleEmitter(particleSystems[1], 50f, Vector3.Zero); }
public virtual void Update(CarActor carActor) { // This method can be over-ridden in other classes, i.e. to keep an offset from the target for a chase camera. // This simple camera is fixed in place (but turns to track the target). // Perhaps this method should be made abstract? Vector3 carPos = carActor.WorldTransform.Translation; this.target_ = carPos; //this.target_ = Vector3.Lerp(target_, carPos, lerpFactor_); viewNeedsUpdate_ = true; // lazy eval >> don't actually update the view matrix until needed. //get behind the target: Vector3 rightOri = carActor.WorldTransform.Forward; // TODO: POSSIBLE ERROR SOURCE Vector3 vel = carActor.LinearVelocity + Vector3.UnitY * 3f; currentFov_ = Lerp(currentFov_, fov_ + (vel.Length() / (CarActor.ForwardSpeed * 2f)), 0.1f); switch (cameraState_) { case CameraState.Chase: position_ = Vector3.Lerp(position_, carPos - (rightOri * offset_ * vel.Length() / 14) - (rightOri * offset_ * 3) + (Vector3.UnitY * offset_), lerpFactor_); //this.currentFov_ = Math.Min(car.Body.Velocity.LengthSquared() / 1000 + this.fov_, MathHelper.Pi - 0.1f); //this.projectionNeedsUpdate_ = true; break; case CameraState.Reverse: position_ = Vector3.Lerp(position_, carPos + (rightOri * offset_ * vel.Length() / 7) + (rightOri * offset_ * 7) + (Vector3.UnitY * offset_), lerpFactor_); break; case CameraState.Dynamic: Vector3 velocity = vel; velocity.Normalize(); velocity.Y = 0; position_ = Vector3.Lerp(position_, carPos - (velocity * offset_ * vel.Length() / 16) - (velocity * offset_ * 4) + (Vector3.UnitY * offset_), lerpFactor_); break; case CameraState.TopDown: position_ = Vector3.Lerp(position_, new Vector3(0f, 200f, 30f), lerpFactor_); break; case CameraState.Count: throw new Exception("Logic error; Camera state set to count"); } this.viewNeedsUpdate_ = true; this.projectionNeedsUpdate_ = true; }
public HUD(Game game, CarActor car, int xEdge, int yEdge) : base(game) { spriteFont = Game.Content.Load <SpriteFont>("GameplayFont"); counter = 0; lapCount = 0; lapPosX = 0; lapPosZ = 0; oldLapPosX = 0; oldLapPosZ = 0; content = game.Content; this.xEdge = xEdge; this.yEdge = yEdge; carActor = car; }
public override void DrawCar(CarActor owner) { // draw the wheels for (int i = 0; i < 2; i++) { DrawWheel(owner.Wheels[i], wheelModelLeft, wheelModelTransformsLeft); } for (int i = 2; i < 4; i++) { DrawWheel(owner.Wheels[i], wheelModelRight, wheelModelTransformsRight); } // draw the car itself. foreach (ModelMesh mesh in carModel_.Meshes) { DrawModelMesh(mesh, carModelTransforms_[mesh.ParentBone.Index] * owner.WorldTransform, true); } }
public abstract void DrawCar(CarActor owner);
public static void updateFromNetwork(this CarActor carActor, PacketReader reader) { // update input first, then state. ORDER is important! carActor.updateInputFromNetwork(reader); carActor.updateStateFromNetwork(reader); }
public static void sendToNetwork(this CarActor carActor, PacketWriter writer) { // send input first, then state. ORDER is important! carActor.sendInputToNetwork(writer); carActor.sendStateToNetwork(writer); }
public static void updateInputFromNetwork(this CarActor carActor, PacketReader reader) { // read values and apply to carActor: // accleration carActor.Acceleration = reader.ReadSingle(); }
public static void sendInputToNetwork(this CarActor carActor, PacketWriter writer) { // read values from carActor and send over network: // accleration writer.Write(carActor.Acceleration); }