Push for Syn
This commit is contained in:
@@ -8,6 +8,7 @@ namespace Platforms
|
||||
{
|
||||
public float xOffset;
|
||||
public float yOffset;
|
||||
public float speed;
|
||||
|
||||
private Vector3 _originalPos;
|
||||
private Vector3 _futurePos;
|
||||
@@ -29,7 +30,7 @@ namespace Platforms
|
||||
_goingToFuturePos = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsPaused)
|
||||
Move(BaseSpeed);
|
||||
@@ -57,21 +58,37 @@ namespace Platforms
|
||||
|
||||
public void Move(float value)
|
||||
{
|
||||
var position = transform.position;
|
||||
switch (_goingToFuturePos)
|
||||
{
|
||||
case true:
|
||||
_platformRigidbody.AddForce(Vector2.left * 100.0f * Time.deltaTime, ForceMode2D.Impulse);
|
||||
_platformRigidbody.MovePosition(new Vector2(position.x + speed * GetDecision(xOffset),
|
||||
position.y + speed * GetDecision(yOffset)));
|
||||
if (Math.Abs(_futurePos.x - transform.position.x) < VerificationOffset &&
|
||||
Math.Abs(_futurePos.y - transform.position.y) < VerificationOffset)
|
||||
_goingToFuturePos = false;
|
||||
break;
|
||||
case false:
|
||||
_platformRigidbody.AddForce(Vector2.left * -100.0f * Time.deltaTime, ForceMode2D.Impulse);
|
||||
_platformRigidbody.MovePosition(new Vector2(position.x + speed * -GetDecision(xOffset),
|
||||
position.y + speed * -GetDecision(yOffset)));
|
||||
if (Math.Abs(_originalPos.x - transform.position.x) < VerificationOffset &&
|
||||
Math.Abs(_originalPos.y - transform.position.y) < VerificationOffset)
|
||||
_goingToFuturePos = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static float GetDecision(float value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case < 0:
|
||||
return -1.0f;
|
||||
case > 0:
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user