protected virtual bool OnCollisionEvent(Fixture fixtureA, Fixture fixtureB, Contact contact) { if (fixtureB.Body.UserFSBodyComponent.gameObject.tag == "Player") { //print ("IMPACT!!"); FVector2 playerPos = fixtureB.Body.Position; FVector2 explosionPos = body.Position; FVector2 result = playerPos - explosionPos; float distance = result.Length(); result.Normalize(); float playerImpact = result.Y * distance * (maxImpactOnPlayer - minImpactOnPlayer) / maxRadius; fixtureB.Body.LinearVelocity = new FVector2(fixtureB.Body.LinearVelocity.X, minImpactOnPlayer + playerImpact); } else { Health objectHealth = fixtureB.Body.UserFSBodyComponent.gameObject.GetComponent <Health>(); if (objectHealth != null) { objectHealth.Damage(GetDamage()); } } return(false); }
public void SetSpeed(float newSpeed) { projectileSpeed = newSpeed; if (normalizedVelocity == null || normalizedVelocity.Length() == 0.0f) { //if no direction, assume straight upwards normalizedVelocity = new FVector2(0.0f, 1.0f); } body.LinearVelocity = new FVector2(projectileSpeed * normalizedVelocity.X, projectileSpeed * normalizedVelocity.Y); }