-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wertz public branch #173
Wertz public branch #173
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"version": "1.0", | ||
"components": [ | ||
"Microsoft.VisualStudio.Workload.ManagedGame" | ||
] | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ public sealed class MovementComponent : MonoBehaviour | |
private const float ORIENTATION_RATE = 8.0f; | ||
private const float TRANSLATION_RATE = 6.0f; | ||
|
||
public Vector3 Velocity; //{ get; private set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can have a private setter |
||
public DataComponent Data { get; private set; } | ||
public Pathfinder Pathfinder { get; private set; } | ||
|
||
|
@@ -74,14 +75,23 @@ private void Update() | |
UpdateCurrentPosition(); | ||
} | ||
|
||
private void UpdateCurrentPosition() | ||
private void UpdateCurrentPosition() | ||
{ | ||
//update position and velocity param of this unit | ||
|
||
|
||
|
||
IndustrialDonut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Vector3 diff = (_moveStrategy.NextPosition - transform.position) * Time.deltaTime; | ||
Vector3 newPosition = transform.position; | ||
newPosition.x += TRANSLATION_RATE * diff.x; | ||
newPosition.y = _moveStrategy.NextPosition.y; | ||
newPosition.z += TRANSLATION_RATE * diff.z; | ||
|
||
Velocity.x = TRANSLATION_RATE * diff.x; | ||
Velocity.y = newPosition.y - transform.position.y; | ||
Velocity.z = TRANSLATION_RATE * diff.z; | ||
Velocity = Velocity / Time.deltaTime; | ||
IndustrialDonut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
transform.position = newPosition; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,23 +184,7 @@ private bool FireWeapon( | |
} | ||
|
||
ShellBehaviour shellBehaviour = shell.GetComponent<ShellBehaviour>(); | ||
shellBehaviour.Initialize(shellDestination, ammo); | ||
|
||
if (isServer) | ||
{ | ||
if (target.IsUnit) | ||
{ | ||
if (isHit && !ammo.IsAoe) | ||
{ | ||
target.Enemy.HandleHit( | ||
ammo.DamageType, ammo.DamageValue, displacement, distance); | ||
} | ||
} | ||
else | ||
{ | ||
// HE damage is applied by the shellBehavior when it explodes | ||
} | ||
} | ||
shellBehaviour.Initialize(shellDestination, ammo, target.Enemy.gameObject.GetComponent<PFW.Units.Component.Movement.MovementComponent>().Velocity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Break up giga long lines if its not too much trouble. Also normally this kind of thing would be done through the UnitDispatcher (add a UnitDispatcher property called 'CurrentMovementSpeed' or something and then have that get the value from movement component; the intent is to avoid non-unit code fiddling with specific components, and have the UnitDispatcher provide a clean interface for outside requests. Then this code just goes |
||
|
||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,20 +37,28 @@ public class ShellBehaviour : MonoBehaviour | |
private float _forwardSpeed => _ammo.Velocity; | ||
private float _verticalSpeed = 0F; | ||
private Vector3 _targetCoordinates; | ||
private Vector3 _targetVelocity; | ||
//targetVelocity is the instantaneous target velocity when this shell is fired. | ||
|
||
private bool _dead = false; | ||
private float _prevDistanceToTarget = 100000F; | ||
private float _initialDistanceToTarget; | ||
|
||
private Ammo _ammo; | ||
|
||
private Collider _launchPlatform; | ||
private bool _justLaunched = true; | ||
|
||
/// <summary> | ||
/// Call in the weapon class to initialize the shell/bullet. | ||
/// </summary> | ||
/// <param name="velocity">In meters.</param> | ||
public void Initialize(Vector3 target, Ammo ammo) | ||
public void Initialize(Vector3 target, Ammo ammo, Vector3 targetVelocity) | ||
{ | ||
_targetCoordinates = target; | ||
_ammo = ammo; | ||
_targetVelocity = targetVelocity; | ||
_initialDistanceToTarget = (_targetCoordinates - transform.position).magnitude; | ||
} | ||
|
||
private void Start() | ||
|
@@ -118,33 +126,61 @@ private void Update() | |
Vector3 worldForward = transform.TransformDirection(Vector3.forward); | ||
worldForward = new Vector3(worldForward.x, 0, worldForward.z); | ||
Vector3 translation = _forwardSpeed * worldForward * Time.deltaTime | ||
+ _verticalSpeed * Vector3.up * Time.deltaTime; | ||
transform.LookAt(transform.position + translation); | ||
+ _verticalSpeed * Vector3.up * Time.deltaTime | ||
+ _targetVelocity * Time.deltaTime; /// * Constants.MAP_SCALE; | ||
///transform.LookAt(transform.position + translation); | ||
transform.Translate( | ||
translation, | ||
Space.World); | ||
|
||
_verticalSpeed -= GRAVITY * Time.deltaTime; | ||
|
||
|
||
// small trick to detect if shell has reached the target | ||
float distanceToTarget = Vector3.Distance(transform.position, _targetCoordinates); | ||
if (distanceToTarget > _prevDistanceToTarget) | ||
if (_justLaunched) | ||
{ | ||
transform.position = _targetCoordinates; | ||
Explode(); | ||
print("instant collision not avoided"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover print |
||
} | ||
_prevDistanceToTarget = distanceToTarget; | ||
|
||
//transform.rotation.SetLookRotation(translation); | ||
_justLaunched = false; | ||
IndustrialDonut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private void OnTriggerEnter(Collider other) | ||
{ | ||
if (other.GetComponent<CaptureZone>() == null) | ||
if (_justLaunched) | ||
{ | ||
Explode(); | ||
_launchPlatform = other; | ||
_justLaunched = false; | ||
print("instant collision avoided now"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover print; if you want to leave it in, use Logger.LogDamage |
||
} | ||
else if(_launchPlatform != other) | ||
{ | ||
UnitDispatcher target = other.gameObject.GetComponentInParent<UnitDispatcher>(); | ||
|
||
if (target != null && !_ammo.IsAoe) | ||
{ | ||
Kinetic(target); | ||
pvutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else if (other.GetComponent<CaptureZone>() == null && _ammo.IsAoe) | ||
IndustrialDonut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Explode(); | ||
} | ||
else | ||
{ | ||
///_verticalSpeed = -_verticalSpeed; | ||
} | ||
} | ||
|
||
} | ||
|
||
private void Kinetic(UnitDispatcher unit) | ||
IndustrialDonut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
_dead = true; | ||
|
||
unit.HandleHit( | ||
_ammo.DamageType, | ||
_ammo.DamageValue, | ||
transform.TransformDirection(Vector3.forward), | ||
_initialDistanceToTarget); | ||
|
||
Destroy(gameObject); | ||
} | ||
|
||
private void Explode() | ||
|
@@ -165,21 +201,18 @@ private void Explode() | |
//emission.enabled = false; | ||
} | ||
|
||
if (_ammo.IsAoe) | ||
{ | ||
List<UnitDispatcher> units = | ||
MatchSession.Current.FindUnitsAroundPoint( | ||
transform.position, _ammo.ExplosionRadius); | ||
List<UnitDispatcher> units = | ||
MatchSession.Current.FindUnitsAroundPoint( | ||
transform.position, _ammo.ExplosionRadius); | ||
|
||
foreach (UnitDispatcher unit in units) | ||
{ | ||
Vector3 vectorToTarget = unit.transform.position - transform.position; | ||
unit.HandleHit( | ||
_ammo.DamageType, | ||
_ammo.DamageValue, | ||
vectorToTarget, | ||
vectorToTarget.magnitude); | ||
} | ||
foreach (UnitDispatcher unit in units) | ||
{ | ||
Vector3 vectorToTarget = unit.transform.position - transform.position; | ||
unit.HandleHit( | ||
_ammo.DamageType, | ||
_ammo.DamageValue, | ||
vectorToTarget, | ||
vectorToTarget.magnitude); | ||
} | ||
|
||
Destroy(gameObject); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we leave this file in or add it to gitignore instead?