when shooting a projectile I execute
private Rigidbody rigid;
private Vector3 currentMovementDirection;
private void FixedUpdate()
{
rigid.velocity = currentMovementDirection;
}
public void InitProjectile(Vector3 startPosition, Quaternion startRotation)
{
transform.position = startPosition;
transform.rotation = startRotation;
currentMovementDirection = transform.forward;
}
I use InitProjectile
as my Start
method because I don't destroy the object, I recycle it and just disable the renderer.
When hitting a object with the projectile, this projectile should get reflected.
I shoot a wall and these walls reflect the objectile multiple times
I think Unity provides something for this
https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html
When the collision is triggered
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == projectile)
{
projectileComponent.ReflectProjectile(); // reflect it
}
}
I want to reflect it by using
public void ReflectProjectile()
{
// Vector3.Reflect(... , ...);
}
but what do I have to use as parameters for Reflect
? It seems I have to rotate the projectile that it changes its movement direction.