in my game, two orbs can clash weapons and in turn would change their orbit direction
// Collision Handling
protected virtual void OnTriggerEnter2D(Collider2D col)
{
if (owner == null) return;
// Ricochet
Weapon otherWeapon = col.GetComponent<Weapon>();
if (otherWeapon != null)
{
Rigidbody2D myOrb = owner.GetComponent<Rigidbody2D>();
Rigidbody2D otherOrb = otherWeapon.owner.GetComponent<Rigidbody2D>();
if (myOrb && otherOrb)
{
Vector2 dir = (myOrb.position - otherOrb.position).normalized;
float bouncePower = 8f;
myOrb.AddForce(dir * bouncePower, ForceMode2D.Impulse);
otherOrb.AddForce(-dir * bouncePower, ForceMode2D.Impulse);
}
// Reverse orbit directions
orbitDir *= -1f;
otherWeapon.orbitDir *= -1f;
Debug.Log($"{name} ricochet! orbitDir={orbitDir}, angle={angle}");
// Flip both sprites
if (spriteRenderer != null)
spriteRenderer.flipX = orbitDir < 0;
if (otherWeapon.spriteRenderer != null)
otherWeapon.spriteRenderer.flipX = otherWeapon.orbitDir < 0;
// Play ricochet sound
PlaySound(ricochetSound);
return;
}
it goes counter clockwise for orbitDir = 1 and clockwise for -1
when debugging, every clash changes the orbit and says what the value is
however, it doesn't change the orbit it at all
but the weird thing is, if i manually change the value during runtime in the inspector, it works
honestly im just so lost on what i could do
@naaboom muted