Thursday, April 2, 2015

unity - How to tilt an object(2D) after collision and the rotate continuously


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...