feat: Random Ball Start Direction
This commit is contained in:
parent
e86cf71010
commit
e7ee460323
|
@ -12,6 +12,7 @@ public class BallBehaviour : BehaviourOverride
|
||||||
public float Speed { get; set; } = 500f;
|
public float Speed { get; set; } = 500f;
|
||||||
public float SpeedUpMultiplier { get; set; } = .0125f;
|
public float SpeedUpMultiplier { get; set; } = .0125f;
|
||||||
|
|
||||||
|
private readonly Random random = new();
|
||||||
private IRigidBody2D rigidBody = null!;
|
private IRigidBody2D rigidBody = null!;
|
||||||
|
|
||||||
public BallBehaviour(Vector2D startDirection, float speed)
|
public BallBehaviour(Vector2D startDirection, float speed)
|
||||||
|
@ -50,7 +51,15 @@ public class BallBehaviour : BehaviourOverride
|
||||||
{
|
{
|
||||||
StateEnable.Enabled = true;
|
StateEnable.Enabled = true;
|
||||||
BehaviourController.GameObject.Transform.Position = Vector2D.Zero;
|
BehaviourController.GameObject.Transform.Position = Vector2D.Zero;
|
||||||
rigidBody.Velocity = Vector2D.One.Normalized * Speed;
|
rigidBody.Velocity = GetRandomDirection() * Speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector2D GetRandomDirection()
|
||||||
|
{
|
||||||
|
const float AllowedRadians = 45f * Syntriax.Engine.Core.Math.DegreeToRadian;
|
||||||
|
float rotation = (float)random.NextDouble() * 2f * AllowedRadians - AllowedRadians;
|
||||||
|
bool isBackwards = (random.Next() % 2) == 1;
|
||||||
|
return Vector2D.Right.Rotate(isBackwards ? rotation + Syntriax.Engine.Core.Math.PI : rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUpdate()
|
protected override void OnUpdate()
|
||||||
|
|
Loading…
Reference in New Issue