- Home /
Question by
ragnarokyt179 · Mar 19, 2019 at 08:35 PM ·
directionprojectilevectorvector2reflect
the projectile reflects 1 time only when it hits something, pls help!
public float speed = 15f;
Vector2 Dir;
Vector2 NDir;
private void Start()
{
Dir = transform.right;
NDir = Dir;
}
private void Update()
{
Rigidbody2D rb = GetComponent<Rigidbody2D>();
if (rb != null)
rb.velocity = NDir * speed;
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.CompareTag("Objects"))
{
NDir = Vector2.Reflect(Dir, other.contacts[0].normal);
}
}
Comment
$$anonymous$$aybe this NDir ins$$anonymous$$d of Dir)?
NDir = Vector2.Reflect(NDir, other.contacts[0].normal);
Answer by ragnarokyt179 · Mar 19, 2019 at 08:36 PM
the projectile hits the wall, then it reflects, but when it hits again it does not reflect
Your answer
Follow this Question
Related Questions
Rotating to a direction is producing a weird result 1 Answer
Move projectile in a specific direction 0 Answers
Clamp Vector direction to one axis 1 Answer
Instantiating a projectile pointing at target. 1 Answer
[Solved]Chaining projectiles 3 Answers