Wormholes Fixed

Fixed issues when jumping to another zone:
All bodies from the old zone are correctly destroyed
Ship controls & UI transfer smoothly to new ship instance
Animation issues are sorted
This commit is contained in:
Reinier Vens 2021-03-05 21:45:32 +00:00
commit 273095afec
8 changed files with 66 additions and 38 deletions

View file

@ -74,7 +74,7 @@ Material:
- _SinePower: 1.25
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _Speed: 10
- _Speed: 20
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1

View file

@ -86,7 +86,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Scale: 5.9919047
- _Scale: 5.396003
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1

View file

@ -18033,7 +18033,7 @@ PrefabInstance:
- target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 55.675
value: 0
objectReference: {fileID: 0}
- target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e,
type: 3}
@ -18964,7 +18964,7 @@ PrefabInstance:
- target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 60.98
value: 0
objectReference: {fileID: 0}
- target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e,
type: 3}

View file

@ -98,7 +98,16 @@ public class ActionGameManager : MonoBehaviour
Zone = new Zone(Settings.PlanetSettings, zonePack);
Zone.Log = s => Debug.Log($"Zone: {s}");
if (CurrentShip != null)
{
Zone.Entities.Add(CurrentShip);
}
SectorRenderer.LoadZone(Zone);
if (CurrentShip != null)
BindToEntity();
}
void Start()
@ -204,6 +213,7 @@ public class ActionGameManager : MonoBehaviour
GenerateLevel();
CurrentShip.ExitWormhole(SectorRenderer.WormholeInstances.Keys.First().Position,
Settings.GameplaySettings.WormholeExitVelocity * ItemManager.Random.NextFloat2Direction());
CurrentShip.Zone = Zone;
};
}
}
@ -215,6 +225,8 @@ public class ActionGameManager : MonoBehaviour
AkSoundEngine.PostEvent(CurrentShip.HeatsinksEnabled ? "UI_Success" : "UI_Fail", gameObject);
};
#region Targeting
_input.Player.TargetReticle.performed += context =>
{
var underReticle = Zone.Entities.Where(x => x != CurrentShip)
@ -241,6 +253,9 @@ public class ActionGameManager : MonoBehaviour
var currentTargetIndex = Array.IndexOf(targets, CurrentShip.Target.Value);
CurrentShip.Target.Value = targets[(currentTargetIndex + targets.Length - 1) % targets.Length];
};
#endregion
#region Trigger Groups
@ -505,32 +520,14 @@ public class ActionGameManager : MonoBehaviour
}
else if (CurrentShip.Parent.TryUndock(CurrentShip))
{
SectorRenderer.PerspectiveEntity = CurrentShip;
Menu.gameObject.SetActive(false);
DockedEntity = null;
DockingBay = null;
//_shipInput = new ShipInput(_input.Player, _currentShip);
DockCamera.enabled = false;
FollowCamera.enabled = true;
FollowCamera.LookAt = SectorRenderer.EntityInstances[CurrentShip].LookAtPoint;
FollowCamera.Follow = SectorRenderer.EntityInstances[CurrentShip].transform;
_articulationGroups = CurrentShip.Equipment
.Where(item => item.Behaviors.Any(x => x.Data is WeaponData && !(x.Data is LauncherData)))
.GroupBy(item => SectorRenderer.EntityInstances[CurrentShip]
.GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])
.GetComponentInParent<ArticulationPoint>()?.Group ?? -1)
.Select((group, index) => {
return (
group.Select(item => CurrentShip.Hardpoints[item.Position.x, item.Position.y]).ToArray(),
group.Select(item => SectorRenderer.EntityInstances[CurrentShip].GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])).ToArray(),
Crosshairs[index]
);
}).ToArray();
foreach (var crosshair in Crosshairs)
crosshair.gameObject.SetActive(false);
foreach (var group in _articulationGroups)
group.crosshair.gameObject.SetActive(true);
BindToEntity();
_lockingIndicators = CurrentShip.GetBehaviors<LockWeapon>()
.Select(x =>
@ -571,6 +568,31 @@ public class ActionGameManager : MonoBehaviour
}
}
private void BindToEntity()
{
SectorRenderer.PerspectiveEntity = CurrentShip;
FollowCamera.LookAt = SectorRenderer.EntityInstances[CurrentShip].LookAtPoint;
FollowCamera.Follow = SectorRenderer.EntityInstances[CurrentShip].transform;
_articulationGroups = CurrentShip.Equipment
.Where(item => item.Behaviors.Any(x => x.Data is WeaponData && !(x.Data is LauncherData)))
.GroupBy(item => SectorRenderer.EntityInstances[CurrentShip]
.GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])
.GetComponentInParent<ArticulationPoint>()?.Group ?? -1)
.Select((group, index) => {
return (
group.Select(item => CurrentShip.Hardpoints[item.Position.x, item.Position.y]).ToArray(),
group.Select(item => SectorRenderer.EntityInstances[CurrentShip].GetBarrel(CurrentShip.Hardpoints[item.Position.x, item.Position.y])).ToArray(),
Crosshairs[index]
);
}).ToArray();
foreach (var crosshair in Crosshairs)
crosshair.gameObject.SetActive(false);
foreach (var group in _articulationGroups)
group.crosshair.gameObject.SetActive(true);
}
public void SaveZone() => File.WriteAllBytes(
Path.Combine(_filePath.FullName, $"{Zone.Data.Name}.zone"), MessagePackSerializer.Serialize(Zone.Pack()));

View file

@ -148,10 +148,10 @@ public class SectorRenderer : MonoBehaviour
public void LoadZone(Zone zone)
{
ClearZone();
_maxDepth = 0;
Zone = zone;
SectorBrushes.localScale = zone.Data.Radius * 2 * Vector3.one;
ClearZone();
foreach(var p in zone.Planets.Values)
LoadPlanet(p);
@ -204,8 +204,14 @@ public class SectorRenderer : MonoBehaviour
public void ClearZone()
{
if (Zone == null) return;
foreach (var wormhole in WormholeInstances.Values) Destroy(wormhole);
WormholeInstances.Clear();
foreach (var entity in Zone.Entities)
{
UnloadEntity(entity);
}
if (Planets.Count > 0)
{
@ -214,10 +220,10 @@ public class SectorRenderer : MonoBehaviour
DestroyImmediate(planet.gameObject);
}
Planets.Clear();
// foreach (var beltObject in _beltObjects.Values)
// {
// beltObject.
// }
foreach (var beltObject in _beltObjects.Values)
{
Destroy(beltObject.Filter);
}
_beltObjects.Clear();
_beltMeshes.Clear();
_beltMatrices.Clear();
@ -446,7 +452,7 @@ public class InstancedMesh
public class AsteroidBeltUI
{
private MeshFilter _filter;
public MeshFilter Filter;
private MeshCollider _collider;
private Vector3[] _vertices;
private Vector3[] _normals;
@ -463,7 +469,7 @@ public class AsteroidBeltUI
{
_belt = belt;
_zone = zone;
_filter = meshFilter;
Filter = meshFilter;
_collider = collider;
var orbit = zone.Orbits[belt.Data.Orbit];
_orbitParent = orbit.Data.Parent;
@ -509,7 +515,7 @@ public class AsteroidBeltUI
_mesh.bounds = new Bounds(Vector3.zero, Vector3.one * maxDist);
_size = maxDist;
_filter.mesh = _mesh;
Filter.mesh = _mesh;
//_collider.sharedMesh = _mesh;
}

View file

@ -222,7 +222,7 @@ public class Ship : Entity
public override void Update(float delta)
{
if (_active && !_exitingWormhole)
if (_active && !_exitingWormhole && !_enteringWormhole)
{
foreach (var thruster in _allThrusters) thruster.Axis = 0;
var rightThrusterTorqueCompensation = abs(RightStrafeTotalTorque) / RightStrafeTorqueThrusters.Length;
@ -287,8 +287,8 @@ public class Ship : Entity
}
else
{
var exitLerp = _wormholeAnimationProgress - ItemManager.GameplaySettings.WormholeExitCurveStart /
(1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
var exitLerp = (_wormholeAnimationProgress - ItemManager.GameplaySettings.WormholeExitCurveStart) /
(1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
exitLerp *= exitLerp; // Square the interpolation variable to produce curve with zero slope at start
Position.xz = _wormholePosition + normalize(_wormholeExitVelocity) * exitLerp * ItemManager.GameplaySettings.WormholeExitRadius;
Rotation = quaternion.LookRotation(

Binary file not shown.

View file

@ -126,6 +126,7 @@
<Compile Include="Assets\Scripts\ServerShared\NIH\RethinkDb.Driver\Generated\Ast\InsertAt.cs" />
<Compile Include="Assets\Scripts\ServerShared\NIH\JsonKnownTypes\JsonDiscriminatorAttribute.cs" />
<Compile Include="Assets\Scripts\ServerShared\Behaviors\Thruster.cs" />
<Compile Include="Assets\Scripts\ServerShared\Wormhole.cs" />
<Compile Include="Assets\Scripts\ServerShared\NIH\RethinkDb.Driver\Generated\Ast\Grant.cs" />
<Compile Include="Assets\Scripts\ServerShared\NIH\LinqFaster\WhereSum.cs" />
<Compile Include="Assets\Scripts\ServerShared\Behaviors\TowingController.cs" />
@ -524,7 +525,6 @@
<Compile Include="Assets\Scripts\ServerShared\NIH\LinqFaster\SequenceEqual.cs" />
<Compile Include="Assets\Scripts\ServerShared\NIH\LinqFaster\Skip.cs" />
<Compile Include="Assets\Scripts\ServerShared\ItemManager.cs" />
<Compile Include="Assets\Scripts\ServerShared\Wormhole.cs" />
<None Include="Assets\Scripts\ServerShared\NIH\LinqFaster\readme.txt" />
<None Include="Assets\Scripts\ServerShared\Economy.Shared.Unity.asmdef" />
<Reference Include="System.Threading.Tasks.Extensions">