Updated moving platform script

This commit is contained in:
OverflowNarhoym
2022-02-23 13:05:30 +01:00
parent 2ab3a57899
commit ff14aea8b2
2 changed files with 185 additions and 5 deletions

View File

@@ -5,25 +5,49 @@ namespace Platforms
{
public class MovingPlatform : MonoBehaviour, IMovement
{
public float xOffeset;
public float yOffset;
private Rigidbody2D _platformRigidbody;
private Vector3 _velocity = Vector3.zero;
private void Awake()
{
_platformRigidbody = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
if (!IsPaused)
Move(BaseSpeed);
}
// PAUSING METHODS
public bool IsPaused { get; }
public bool IsPaused { get; private set; }
public void Pause()
{
throw new System.NotImplementedException();
IsPaused = true;
_platformRigidbody.simulated = !IsPaused;
}
public void Resume()
{
throw new System.NotImplementedException();
IsPaused = false;
_platformRigidbody.simulated = !IsPaused;
}
// MOVEMENT METHODS
public float BaseSpeed { get; set; }
public void Move(float value)
{
throw new System.NotImplementedException();
var position = transform.position;
var targetPosition = new Vector3(position.x + xOffeset, position.y + yOffset, 0.0f);
position = Vector3.SmoothDamp(position, targetPosition, ref _velocity, 1.0f);
transform.position = position;
}
}
}
}