I am having trouble rotating and object after collision. The object only transforms to the given angle of rotation once and stops. I would like to achieve in a way that after it has collided with the player object it rotates continuously till its killed after exiting the screen. The OnCollisionEnter2D(Collision2D collision)
can't achieve this.
How can I achieve it using the FixedUpdate
function?
Here is the code:
namespace Assets.scripts
{
public class Barmovementscript : MonoBehaviour
{
public float Tilt;
private void FixedUpdate()
{
}
// upon collision the object rotates in a clockwise direction.
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag == "Player")
{
Tilt += Time.deltaTime * -10;
gameObject.transform.rotation = Quaternion.Euler(0, 0, Tilt);
}
}
}
}
No comments:
Post a Comment