- Home /
Decal Rotation after instantiation
The below code is from a quick game I'm creating to test out features of Unity. I have the code creating a decal when it detects a collision with another object. The issue is when it created the decal its facing up (Y direction) in a 3d game. I have tried a few solutions but can't get it to rotate to face the same direction as the object it strikes. Example object hits a wall facing the player, obviously we would want the decal to spawn facing the player.....my issue is they all spawn face up. I looked at a few older questions posted with similar issues but can't get it to cooperate so any help would be great.
else
{
Debug.Log ("collision detected");
//Instantiate (splat, transform.position, Quaternion.Euler(collision.gameObject.transform.forward));
//Instantiate (splat, transform.position, Quaternion.LookRotation(collision.gameObject.transform.forward, collision.gameObject.transform.transform.up));
//Instantiate (splat, transform.position, collision.gameObject.transform.rotation);
if (collision.gameObject.tag == "Splat")
{
Debug.Log ("Splat Sprite struck, ignorning creationg of splatCreated.");
Destroy(this.gameObject);
}
else if(collision.gameObject.tag == "Weapon")
{
Debug.Log("Weapon collision detected, ignorning splat and destroy.");
}
else
{
GameObject splatCreated = Instantiate (splat, transform.position, Quaternion.Euler (collision.gameObject.transform.forward));
//destroy splat gameobject created after 1 second
Destroy (splatCreated, 1);
//destroy paintball gameObject on impact with any collision
Destroy(this.gameObject);
}
}
I'm having this same issue. It pains me to see that this question has been up for over a year and nobody has answered it... I really need to figure out this decal rotation as well.