public void SendHorizontalInputOnChange() { var translation = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <Translation>(this.systemManager.Hero); var data = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <CarComponent>(this.systemManager.Hero); if (inputSnapshots.SideInputs.Count == 0) { return; } var input = inputSnapshots.SideInputs.Dequeue(); if (input.SteeringDirection == this.lastSentSteertingDirection) { return; } object[] content = new object[] { input.SteeringDirection, input.ServerTimestamp, translation.Value.x }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others }; PhotonNetwork.RaiseEvent(2, content, raiseEventOptions, SendOptions.SendReliable); this.lastSentSteertingDirection = input.SteeringDirection; }
private void SyncHorionztal() { var input = default(SteeringPress); if (this.recievedSteeringInputs.Count > 0) { input = this.recievedSteeringInputs.Dequeue(); this.currentEnemySteering = input.SteeringDirection; } //TODO: Switch if (this.currentEnemySteering == SteeringDirection.Left) { this.enemyCarX -= Settings.SteeringSenstivity * Time.deltaTime * 20; this.previousEnemySteering = SteeringDirection.Left; } else if (this.currentEnemySteering == SteeringDirection.Right) { this.enemyCarX += Settings.SteeringSenstivity * Time.deltaTime * 20; this.previousEnemySteering = SteeringDirection.Right; } else if (this.currentEnemySteering == SteeringDirection.Straight && this.previousEnemySteering != SteeringDirection.Straight) { this.enemyCarX = input.X; this.previousEnemySteering = SteeringDirection.Straight; } this.testTarget.transform.position = new Vector3(this.enemyCarX, this.testTarget.transform.position.y, this.testTarget.transform.position.z); }
public void Add(MoveDirection moveDirection, SteeringDirection steeringDirection) { this.ForwardInputs.Enqueue(new InputPress { MoveDirection = moveDirection, ServerTimeStamp = Photon.Pun.PhotonNetwork.ServerTimestamp }); this.SideInputs.Enqueue(new SteeringPress { SteeringDirection = steeringDirection, ServerTimestamp = Photon.Pun.PhotonNetwork.ServerTimestamp }); }
public void HandleSteering(ref CarComponent carComponent, ref Rotation rotation) { if (carComponent.Speed < 0.1) { this.CurrentSteeringDirection = SteeringDirection.Straight; } var tiltingAngle = (carComponent.Speed / MaxSpeed) * 0.1f; if (this.CurrentSteeringDirection == SteeringDirection.Right) { carComponent.SteeringIndex = this.SteeringSenstivity; } else if (this.CurrentSteeringDirection == SteeringDirection.Left) { carComponent.SteeringIndex = -this.SteeringSenstivity; } else { carComponent.SteeringIndex = 0; } }