my player uses rigidbody.velocity to move, and also have an alien that explodes, and also has an explosion effect that pushes objects away, look here what the problem is: bandicam 2019-08-11 23-21-37-066.mp4 - Google Drive as you see in the video, all mobs flew away, only the player because i’m moving him using rigidbody, i tried to disable my controller script, and it worked, anyone help pls, here’s my movement piece of code:
void FixedUpdate()
{
if (horizontal != 0 && vertical != 0)
{
rb.velocity = new Vector2((horizontal * speed) * speedLimiter, (vertical * speed) * speedLimiter);
}
else
{
rb.velocity = new Vector2(horizontal * speed, vertical * speed);
}
}
and here is the explosion piece of code:
public override void FixedUpdate() {
base.FixedUpdate();
checkDistance();
}
void checkDistance() {
if (player != null) {
if (Vector2.Distance(transform.position, player.position) <= 1.75f)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);
foreach(Collider2D collider in colliders)
{
Rigidbody2D rb = collider.GetComponent<Rigidbody2D>();
if(rb != null)
{
AddExplosionForce(rb, explosionForce, transform.position, radius);
}
}
GameObject instance = SpawnObject.WithRotation(WormSplashEffect, transform);
Destroy(instance, 1f);
Destroy(gameObject);
}
}
}
public void AddExplosionForce(Rigidbody2D body, float explosionForce, Vector3 explosionPosition, float explosionRadius)
{
var dir = (body.transform.position - explosionPosition);
float wearoff = 1 - (dir.magnitude / explosionRadius);
body.AddForce(dir.normalized * explosionForce * wearoff);
}