public void BounceCollision(BasicPhysicsObject thisObject, BasicPhysicsObject other) { if (thisObject.PhysicsProperties.canBounce) { Vector2 tangent; tangent.y = -(other.transform.position.x - thisObject.transform.position.x); tangent.x = other.transform.position.y - thisObject.transform.position.y; tangent.Normalize(); Vector2 relativeVelocity = new Vector2(thisObject.Velocity.x - other.Velocity.x, thisObject.Velocity.y - other.Velocity.y); float lenght = Vector2.Dot(relativeVelocity, tangent); Vector2 velocityComponentOnTangent; velocityComponentOnTangent = tangent * lenght; Vector2 velocityComponentPerpendicularToTangent = relativeVelocity - velocityComponentOnTangent; thisObject.Velocity.x -= 2 * velocityComponentPerpendicularToTangent.x; thisObject.Velocity.y -= 2 * velocityComponentPerpendicularToTangent.y; } else { return; } }
public void Shoot() { eventBus.Publish(new OnBulletShooted(gameObject.GetComponent <Player>())); //Evento de quando uma bala e disparada, fazendo todos os jogadores pararem de efetuar inputs. var bullet = bulletFactory.Create(); if (bullet != null) { bullet.transform.position = FirePosition.transform.position; bullet.transform.rotation = gameObject.transform.rotation; Bullet info = bullet.GetComponent <Bullet>(); info.Shooter = gameObject; info.bulletInfo = ChoosedBullet; SpriteRenderer SR = bullet.GetComponent <SpriteRenderer>(); SR.color = ChoosedBullet.BulletColor; BasicPhysicsObject physicsProperties = bullet.GetComponent <BasicPhysicsObject>(); physicsProperties.PhysicsProperties = ChoosedBullet.CustomPhysicsPropertys; physicsProperties.Velocity = FirePosition.transform.localScale.normalized.x * -transform.right * ChoosedBullet.BulletSpeed; } }
void Start() { try { bpo = GetComponent <BasicPhysicsObject>(); } catch { Debug.LogError("BasicPhysicsObject não encontrado. Por favor, adicionar CustomCircleCollider ou CustomSquareCollider"); DestroyImmediate(this); } }
public void StopOnCollide(BasicPhysicsObject toStop, BasicPhysicsObject other) // Faz o objeto parar de se mover caso colida { //TOFIX Ao colidir com as paredes, o player se afasta muito da parede float distanceBetweenCircles = Vector2.Distance(toStop.transform.position, other.gameObject.transform.position); float angle = Mathf.Atan2(toStop.transform.position.x - other.gameObject.transform.position.x, toStop.transform.position.y - other.gameObject.transform.position.y); float distanceToMove = (toStop.transform.localScale.x + other.transform.localScale.x) - distanceBetweenCircles; toStop.transform.position += new Vector3(0, Mathf.Cos(angle) * distanceToMove / 4, 0); //divindo por 4 para reduzir a distancia a qual o objeto se afasta da parede ao colidir }
public void RemoveColliderFromBuffer(BasicPhysicsObject bpo) { collidersInScene.Remove(bpo); }
public void AddColliderToBuffer(BasicPhysicsObject bpo) { collidersInScene.Add(bpo); }
public OnPhysicsObjectCollide(BasicPhysicsObject collider, BasicPhysicsObject collided) { Collider = collider; Collided = collided; }