version 1.3
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class SpaceshipNetworkBot : NetworkBehaviour
|
||||
{
|
||||
|
||||
@@ -11,20 +14,53 @@ public class SpaceshipNetworkBot : NetworkBehaviour
|
||||
public string pname;
|
||||
public Text nameTxt;
|
||||
public float movingSpeed;
|
||||
public float minSpeed;
|
||||
public float maxSpeed;
|
||||
public Transform curTarget;
|
||||
public TrailMgrBot trailMgr;
|
||||
public GameObject DeathEffect;
|
||||
public LayerMask pickupsLayer;
|
||||
[SyncVar]
|
||||
public int Scores = 0;
|
||||
public float up;
|
||||
|
||||
[SyncVar(hook = nameof(OnSetupIndexChanged))]
|
||||
public int SelectedSetupIndex;
|
||||
void OnSetupIndexChanged(int old, int value){
|
||||
GetComponent<SpriteRenderer>().sprite = botSetups[value].skins[SelectedSkinIndex];
|
||||
}
|
||||
|
||||
[SyncVar(hook = nameof(OnSkinIndexChanged))]
|
||||
public int SelectedSkinIndex;
|
||||
void OnSkinIndexChanged(int old, int value){
|
||||
GetComponent<SpriteRenderer>().sprite = botSetups[SelectedSetupIndex].skins[value];
|
||||
}
|
||||
|
||||
public float up;
|
||||
public BotSetup[] botSetups;
|
||||
void OnPnameChanged(string oldName, string newName){
|
||||
nameTxt.text = newName;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
|
||||
public void InitRandomBot(){
|
||||
pname = BotsHiveMind.LeaseName(pname.Length > 0 ? pname : null);
|
||||
nameTxt.text = pname;
|
||||
|
||||
int luck = Random.Range(0,100);
|
||||
BotSetup selectedSetup = botSetups[0];
|
||||
for(int i=0; i < botSetups.Length; i++){
|
||||
BotSetup setup = botSetups[i];
|
||||
if(setup.rarity < luck && setup.rarity > selectedSetup.rarity){
|
||||
selectedSetup = setup;
|
||||
SelectedSetupIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
SelectedSkinIndex = Random.Range(0, selectedSetup.skins.Length);
|
||||
GetComponent<SpriteRenderer>().sprite = selectedSetup.skins[SelectedSkinIndex];
|
||||
|
||||
movingSpeed = Random.Range(selectedSetup.minSpeed, selectedSetup.maxSpeed);
|
||||
|
||||
// movingSpeed = Random.Range(minSpeed, maxSpeed);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -33,21 +69,9 @@ public class SpaceshipNetworkBot : NetworkBehaviour
|
||||
if(!isServer){return;}
|
||||
HandleMovement();
|
||||
CheckForPickups();
|
||||
ChangeName();
|
||||
// ChangeName();
|
||||
}
|
||||
|
||||
float nameChangeTimer = 1000;
|
||||
float nameChangeTime = 0;
|
||||
void ChangeName(){
|
||||
nameChangeTimer+=Time.deltaTime;
|
||||
|
||||
if(nameChangeTimer > nameChangeTime){
|
||||
nameChangeTimer = 0;
|
||||
nameChangeTime = Random.Range(1000, 2000);
|
||||
pname = BotsHiveMind.LeaseName(pname.Length > 0 ? pname : null);
|
||||
nameTxt.text = pname;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckForPickups(){
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 3, pickupsLayer);
|
||||
@@ -191,7 +215,8 @@ public class SpaceshipNetworkBot : NetworkBehaviour
|
||||
int leftoverAmount = (int)((float)Scores/4f);
|
||||
Debug.Log("Bot " + pname + " Left " + leftoverAmount + " Stars");
|
||||
MinigameManager.instance.SpawnLeftoverPickups(transform.position, leftoverAmount);
|
||||
|
||||
MinigameManager.instance.DestroyBot(this);
|
||||
return;
|
||||
RpcDie(transform.position);
|
||||
Scores = 0;
|
||||
trailTime = 0;
|
||||
@@ -242,6 +267,12 @@ public static class BotsHiveMind{
|
||||
|
||||
return chosenName;
|
||||
}
|
||||
|
||||
|
||||
public static void ReturnName(string name){
|
||||
PooledNames.Add(name);
|
||||
ActiveNames.Remove(name);
|
||||
}
|
||||
private static Dictionary<SpaceshipController, SpaceshipNetworkBot> leased = new Dictionary<SpaceshipController, SpaceshipNetworkBot>();
|
||||
|
||||
public static Dictionary<SpaceshipController, SpaceshipNetworkBot> Leased {
|
||||
@@ -264,4 +295,22 @@ public static class BotsHiveMind{
|
||||
leased.Add(player,bot);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void RetrunPlayer(SpaceshipController player){
|
||||
if(leased.ContainsKey(player)){
|
||||
leased.Remove(player);
|
||||
}
|
||||
|
||||
Debug.Log("Trying to return a player to hive mind pool. But no one was borrowing them");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class BotSetup{
|
||||
public float minSpeed;
|
||||
public float maxSpeed;
|
||||
public Sprite[] skins;
|
||||
[Range(0,100)]
|
||||
public int rarity;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using System;
|
||||
using Mirror;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Threading.Tasks;
|
||||
using Debug = CustomLogger.Debug;
|
||||
|
||||
public class MatchMaker : MonoBehaviour
|
||||
{
|
||||
@@ -85,41 +86,64 @@ public class MatchMaker : MonoBehaviour
|
||||
void UpdatePlayerCount(){
|
||||
playerCountTxt.text = $"EU: {euPlayers}\nSGP: {sgpPlayers}\nUSA: {usPlayers}";
|
||||
}
|
||||
|
||||
int port =-1;
|
||||
IEnumerator FetchMatchmake(){
|
||||
#region old
|
||||
// WWWForm form = new WWWForm();
|
||||
// form.AddField("name", DBmanager.username);
|
||||
// form.AddField("region", RegionManager.selectedServer.name);
|
||||
|
||||
// WWW req = new WWW(DBmanager.phpRoot+"matchmake.php", form);
|
||||
// yield return req;
|
||||
// Debug.Log(req.text);
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", DBmanager.username);
|
||||
form.AddField("region", RegionManager.selectedServer.name);
|
||||
// try{
|
||||
// int port = int.Parse(req.text);
|
||||
// if(port > 5000){
|
||||
// Debug.Log("Got the port, Lets go!");
|
||||
// AutoConnect.serverPort = port;
|
||||
// LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
// }
|
||||
// }catch{
|
||||
|
||||
WWW req = new WWW(DBmanager.phpRoot+"matchmake.php", form);
|
||||
yield return req;
|
||||
Debug.Log(req.text);
|
||||
// if(req.text.Contains(DBmanager.username) && !loadedScene){
|
||||
// int port
|
||||
// //Room created!
|
||||
// // isServer= req.text.Substring(0,DBmanager.username.Length) == DBmanager.username;
|
||||
// // serverName=req.text;
|
||||
// // AutoConnect.serverName = serverName;
|
||||
// // AutoConnect.isRankedServer = isServer;
|
||||
// // AutoConnect.isRanked = true;
|
||||
// Debug.Log($"Room created! [{req.text}] am I the server? : ");
|
||||
|
||||
// LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
|
||||
// }else{
|
||||
// //Waiting
|
||||
// }
|
||||
#endregion
|
||||
|
||||
try{
|
||||
int port = int.Parse(req.text);
|
||||
if(port > 5000){
|
||||
WWW req = new WWW($"http://{RegionManager.selectedServer.ip}:1601/?password=xyz@123&&username=" + DBmanager.username);
|
||||
yield return req;
|
||||
|
||||
Debug.Log("Matchmaker: "+req.text);
|
||||
if(req.text.Contains("{")){
|
||||
MatchmakerResponse response = JsonUtility.FromJson<MatchmakerResponse>(req.text);
|
||||
// if()
|
||||
if(port < 0){
|
||||
confirmRoom(response);
|
||||
}else if(port > 0){
|
||||
Debug.Log("Got the port, Lets go!");
|
||||
AutoConnect.serverPort = port;
|
||||
AutoConnect.serverPort = response.Port;
|
||||
LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
}
|
||||
}catch{
|
||||
Debug.Log(response.ToString());
|
||||
|
||||
port = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
MatchmakerResponse init_response;
|
||||
int responseCounter =0;
|
||||
void confirmRoom(MatchmakerResponse response){
|
||||
if(responseCounter == 0){
|
||||
init_response = response;
|
||||
}
|
||||
responseCounter++;
|
||||
|
||||
if(responseCounter > 5){
|
||||
responseCounter=0;
|
||||
if(response.Players.Length == 2){
|
||||
//Confirm room
|
||||
port = response.Port;
|
||||
}else{
|
||||
port = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,3 +185,21 @@ public class MatchMaker : MonoBehaviour
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MatchmakerResponse{
|
||||
public MatchmakerPlayerEntry[] Players;
|
||||
public int Port;
|
||||
public long InitTime;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonUtility.ToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MatchmakerPlayerEntry{
|
||||
public string Name;
|
||||
public long LastSeen;
|
||||
}
|
||||
@@ -31,8 +31,12 @@ public class MinigameManager : NetworkBehaviour
|
||||
float safeZoneShrinkSpeed;
|
||||
[SerializeField] private PickupSetting[] PickupItems;
|
||||
public PickupSetting[] pickupItems => PickupItems;
|
||||
|
||||
[Header("Bots")]
|
||||
public GameObject botPrefab;
|
||||
public int maxBots;
|
||||
public List<SpaceshipNetworkBot> bots;
|
||||
public GameObject DeathEffect;
|
||||
// public GameObject starPrefab;
|
||||
// public int maxMoons, maxStars = 100;
|
||||
// public int maxTweps = 2;
|
||||
@@ -113,23 +117,22 @@ public class MinigameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
void Start(){
|
||||
AudioManager.instnace.SetCustomMusic(musicClips[Random.Range(0,musicClips.Length)]);
|
||||
|
||||
if(!isServer){
|
||||
Application.targetFrameRate = 60;
|
||||
}else{
|
||||
Debug.Log("Setting framerate to 35");
|
||||
Application.targetFrameRate = 35;
|
||||
}
|
||||
|
||||
if(isServer && !isRanked){
|
||||
bots = new List<SpaceshipNetworkBot>();
|
||||
for(int i =0; i < 5; i++){
|
||||
GameObject newBot = Instantiate(botPrefab, getRandomPointInCirlce(Vector3.zero, 150), Quaternion.identity);
|
||||
bots.Add(newBot.GetComponent<SpaceshipNetworkBot>());
|
||||
newBot.GetComponent<SpaceshipNetworkBot>().pname = newBot.GetComponent<SpaceshipNetworkBot>().Names[i];
|
||||
NetworkServer.Spawn(newBot);
|
||||
for(int i =0; i < maxBots; i++){
|
||||
SpawnBot();
|
||||
}
|
||||
}
|
||||
AudioManager.instnace.SetCustomMusic(musicClips[Random.Range(0,musicClips.Length)]);
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -140,7 +143,9 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
HandlePickupSpawn();
|
||||
KillOutOfBoundsPlayers();
|
||||
if(isRanked){RankedMechanics();}
|
||||
if(isRanked){RankedMechanics();}else{
|
||||
HandleBots();
|
||||
}
|
||||
}
|
||||
public float timeElapsed => (float)(NetworkTime.time - startedTime);
|
||||
bool shrinkStarted =false;
|
||||
@@ -471,6 +476,44 @@ public class MinigameManager : NetworkBehaviour
|
||||
public void UpdateMaterialValues(){
|
||||
metalTxt.text = DBmanager.Metal.ToString();
|
||||
}
|
||||
|
||||
|
||||
void HandleBots(){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
float m_maxBots = maxBots - players.Length;
|
||||
|
||||
if(bots.Count < m_maxBots){
|
||||
SpawnBot();
|
||||
}else if(bots.Count - m_maxBots > 0){
|
||||
DestroyBot(bots[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnBot(){
|
||||
Debug.Log("Spawning bot");
|
||||
GameObject newBot = Instantiate(botPrefab, getRandomPointInCirlce(Vector3.zero, 150), Quaternion.identity);
|
||||
SpaceshipNetworkBot bot = newBot.GetComponent<SpaceshipNetworkBot>();
|
||||
bots.Add(bot);
|
||||
bot.pname = BotsHiveMind.LeaseName();
|
||||
bot.InitRandomBot();
|
||||
NetworkServer.Spawn(newBot);
|
||||
}
|
||||
|
||||
public void DestroyBot(SpaceshipNetworkBot bot){
|
||||
RpcShowDeathEffect(bot.transform.position);
|
||||
NetworkServer.Destroy(bot.gameObject);
|
||||
bots.Remove(bot);
|
||||
BotsHiveMind.ReturnName(bot.pname);
|
||||
if(bot.curTarget.GetComponent<SpaceshipController>() != null){
|
||||
BotsHiveMind.RetrunPlayer(bot.curTarget.GetComponent<SpaceshipController>());
|
||||
}
|
||||
Debug.Log("Destroyed bot " + bot.pname + ". Left bots: " +bots.Count);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcShowDeathEffect(Vector3 position){
|
||||
EffectPool.Spawn(DeathEffect, position);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using CustomExtensions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class PickupItem : NetworkBehaviour
|
||||
{
|
||||
@@ -102,7 +103,7 @@ public class PickupItem : NetworkBehaviour
|
||||
transform.position = newPosition;
|
||||
position= newPosition;
|
||||
gameObject.SetActive(true);
|
||||
Debug.LogWarning("Repositoning pickup");
|
||||
// Debug.LogWarning("Repositoning pickup");
|
||||
}
|
||||
|
||||
public void Deactivate(Transform playerPos){
|
||||
@@ -123,17 +124,22 @@ public class PickupItem : NetworkBehaviour
|
||||
NetworkServer.Destroy(gameObject);
|
||||
|
||||
}else{
|
||||
StartCoroutine(MoveToPlayer(playerPos));
|
||||
MoveToPlayer(playerPos);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator MoveToPlayer(Transform position){
|
||||
async void MoveToPlayer(Transform position){
|
||||
float speed = 0.02f;
|
||||
while(Vector3.Distance(position.position, transform.position) > 1f){
|
||||
transform.position = Vector3.Lerp(transform.position, position.position, speed);
|
||||
speed+= 0.02f;
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
try{
|
||||
while(transform != null && Vector3.Distance(position.position, transform.position) > 1f){
|
||||
transform.position = Vector3.Lerp(transform.position, position.position, speed);
|
||||
speed+= 0.02f;
|
||||
// yield return new WaitForSeconds(0.01f);
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}catch{
|
||||
Debug.Log("Target lost");
|
||||
}
|
||||
if(!isServer){
|
||||
ParticleSystem particle = EffectPool.Spawn(PickupEffect, transform.position).GetComponent<ParticleSystem>();
|
||||
|
||||
@@ -8,7 +8,7 @@ public class RankedSplash : MonoBehaviour
|
||||
public int playerCountRequired;
|
||||
public TMP_Text statusTxt;
|
||||
public GameObject controlsUI;
|
||||
public float startTimer = 120;
|
||||
public float startTimer = 60;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -28,23 +28,26 @@ public class RankedSplash : MonoBehaviour
|
||||
if(gameObject.activeSelf){
|
||||
if(startTimer > 0){
|
||||
startTimer-= Time.deltaTime;
|
||||
if(startTimer <= 45 && players.Length == 0){
|
||||
if(startTimer <= 10 && players.Length == 0){
|
||||
MessageDialog.instance.ShowMessage("Error", "Connection to the server timed out");
|
||||
LoadingScreen.instance.LoadLevel("GameScene");
|
||||
startTimer = -100;
|
||||
Feedbacks.Send("Ranked Didn't start", "Couldn't Connect to server", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText);
|
||||
|
||||
}
|
||||
if(startTimer <= 45 && players.Length == 1){
|
||||
if(startTimer <= 10 && players.Length == 1){
|
||||
Debug.Log("Timed out");
|
||||
|
||||
MinigameManager.instance.EnemyForfeit();
|
||||
players[0].WonRanked();
|
||||
startTimer = -100;
|
||||
|
||||
Feedbacks.Send("Ranked Didn't start", "Opponent didnt connect", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText);
|
||||
}
|
||||
}else{
|
||||
if(SceneData.localPlayer.GetComponent<SpaceshipController>().ready){
|
||||
MinigameManager.instance.EnemyForfeit();
|
||||
SceneData.localPlayer.GetComponent<SpaceshipController>().WonRanked();
|
||||
Feedbacks.Send("Ranked Didn't start", "Opponent didnt connect, I was ready", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText);
|
||||
}
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
@@ -127,13 +127,14 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
}
|
||||
|
||||
void OnUpgradeSpeed(){
|
||||
bool Affordable = DBmanager.Coins >= nextSpeedStats.goldCost && DBmanager.Metal >= nextSpeedStats.metalCost;
|
||||
bool Affordable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost;
|
||||
if(!Affordable){
|
||||
MessageDialog.instance.ShowMessage("Error","Not enough resources to upgrade.");
|
||||
return;
|
||||
}
|
||||
Debug.Log("Upgrade cost: " + nextRocketLevel.goldCost + "golds " + nextRocketLevel.metalCost + "m");
|
||||
|
||||
DBmanager.UpgradeRocketSpeed(selectedRocket, nextSpeedStats);
|
||||
DBmanager.UpgradeRocketSpeed(selectedRocket, nextRocketLevel);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.UpgradeRocket();
|
||||
@@ -148,13 +149,14 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
}
|
||||
|
||||
void OnUpgradeBoost(){
|
||||
bool Affordable = DBmanager.Coins >= nextBoostStats.goldCost && DBmanager.Metal >= nextBoostStats.metalCost;
|
||||
bool Affordable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost;
|
||||
if(!Affordable){
|
||||
MessageDialog.instance.ShowMessage("Error","Not enough resources to upgrade.");
|
||||
return;
|
||||
}
|
||||
Debug.Log("Upgrade cost: " + nextRocketLevel.goldCost + "golds " + nextRocketLevel.metalCost + "m");
|
||||
|
||||
DBmanager.UpgradeRocketBoost(selectedRocket, nextBoostStats);
|
||||
DBmanager.UpgradeRocketBoost(selectedRocket, nextRocketLevel);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.UpgradeRocket();
|
||||
@@ -171,13 +173,14 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
}
|
||||
|
||||
void OnUpgradeEnergy(){
|
||||
bool Affordable = DBmanager.Coins >= nextEnergyStats.goldCost && DBmanager.Metal >= nextEnergyStats.metalCost;
|
||||
bool Affordable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost;
|
||||
if(!Affordable){
|
||||
MessageDialog.instance.ShowMessage("Error","Not enough resources to upgrade.");
|
||||
return;
|
||||
}
|
||||
Debug.Log("Upgrade cost: " + nextRocketLevel.goldCost + "golds " + nextRocketLevel.metalCost + "m");
|
||||
|
||||
DBmanager.UpgradeRocketEnergy(selectedRocket, nextEnergyStats);
|
||||
DBmanager.UpgradeRocketEnergy(selectedRocket, nextRocketLevel);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.UpgradeRocket();
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using CustomExtensions;
|
||||
using Debug = CustomLogger.Debug;
|
||||
|
||||
public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
public LayerMask pickupsLayer;
|
||||
@@ -58,6 +60,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
private float minTimeBetweenTicks;
|
||||
private const float SERVER_TICK_RATE = 30f;
|
||||
private const int BUFFER_SIZE = 2048;
|
||||
private const bool CUSTOM_NET_TRANSFORM = false;
|
||||
private float ERROR_THRESHOLD =0.25f;
|
||||
private int MIN_ERROR_COUNT = 10;
|
||||
public bool showDebugHUD = false;
|
||||
@@ -256,7 +259,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
if (joystick == null) { joystick = FindObjectOfType<Joystick>(); }
|
||||
FindObjectOfType<CameraFollower>().SetTarget(transform);
|
||||
string myName = DBmanager.displayName;
|
||||
string myName = DBmanager.DisplayName;
|
||||
SceneData.localPlayer = gameObject;
|
||||
SceneData.OnBoostDown.AddListener(OnBoostDown);
|
||||
SceneData.OnBoostUp.AddListener(OnBoostUp);
|
||||
@@ -359,20 +362,33 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
SceneData.SetTimerTxt(survivalTime);
|
||||
|
||||
body.position = Vector3.Lerp(body.position,targetState.Position,MovementSmoothnessFactor * movingSpeed * Vector2.Distance(targetState.Position, body.position));
|
||||
body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
|
||||
if(CUSTOM_NET_TRANSFORM){
|
||||
body.position = Vector3.Lerp(body.position,targetState.Position,MovementSmoothnessFactor * movingSpeed * Vector2.Distance(targetState.Position, body.position));
|
||||
body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
|
||||
}
|
||||
// Debug.Log(lastTime - currentTick);
|
||||
lastTime = targetState.Tick;
|
||||
CameraFollower.UpdateFrame();
|
||||
if(CUSTOM_NET_TRANSFORM){
|
||||
CameraFollower.UpdateFrame();
|
||||
}
|
||||
}
|
||||
|
||||
timer += Time.deltaTime;
|
||||
// return;
|
||||
|
||||
}
|
||||
|
||||
while(timer >= minTimeBetweenTicks){
|
||||
timer -= minTimeBetweenTicks;
|
||||
HandleTick();
|
||||
currentTick++;
|
||||
}
|
||||
void FixedUpdate(){
|
||||
// timer += Time.deltaTime;
|
||||
|
||||
// while(timer >= minTimeBetweenTicks){
|
||||
// timer -= minTimeBetweenTicks;
|
||||
// HandleTick();
|
||||
// currentTick++;
|
||||
// }
|
||||
if (MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted) { return; }
|
||||
|
||||
HandleTick();
|
||||
currentTick++;
|
||||
}
|
||||
Vector3 serverPosition => serverStateBuffer[bufferIndex].Position;
|
||||
Vector3 clientPosition => clientStateBuffer[bufferIndex].Position;
|
||||
@@ -414,7 +430,9 @@ public class SpaceshipController : NetworkBehaviour
|
||||
// body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
|
||||
}else if (isServer){
|
||||
HandleInput(m_Input);
|
||||
// RpcUpdateOnClient(body.position, body.rotation, m_Input);
|
||||
if(CUSTOM_NET_TRANSFORM){
|
||||
RpcUpdateOnClient(body.position, body.rotation, m_Input);
|
||||
}
|
||||
|
||||
CheckForPickups();
|
||||
}else{
|
||||
@@ -517,6 +535,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
[ClientRpc]
|
||||
void RpcRubberband(Vector3 m_position, Quaternion m_rotation){
|
||||
return;
|
||||
if(!CUSTOM_NET_TRANSFORM){return;}
|
||||
PlayerState serverState = new PlayerState(){Tick=0, Position = m_position, Rotation = m_rotation};
|
||||
PlayerState clientState = new PlayerState(){Tick=0, Position = transform.position, Rotation = transform.rotation};
|
||||
float diff = serverState.Difference(clientState);
|
||||
@@ -615,7 +634,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
|
||||
SpaceshipController deadPlayer = hit.GetComponent<SpaceshipController>();
|
||||
Debug.Log("got hit by player? : " + (deadPlayer != null));
|
||||
// Debug.Log("got hit by player? : " + (deadPlayer != null));
|
||||
if (deadPlayer != null && !deadPlayer.dead && (NetworkTime.time - deadPlayer.startedTime) > 5)
|
||||
{ // <-- okay we killed someone | KILLCODE
|
||||
// deadPlayer.RpcShowDeathEffect(deadPlayer.transform.position);
|
||||
@@ -627,11 +646,11 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
|
||||
SpaceshipNetworkBot deadBot = hit.GetComponent<SpaceshipNetworkBot>();
|
||||
Debug.Log("got hit by bot? : " + (deadPlayer != deadBot));
|
||||
// Debug.Log("got hit by bot? : " + (deadPlayer != deadBot));
|
||||
|
||||
if(deadBot != null){
|
||||
deadBot.Die();
|
||||
|
||||
Kills++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user