var spark : GameObject;
private var counter=0;
private var grav = 0;
private var targetRotation : Quaternion;
function Start(){targetRotation=transform.rotation;}
function Update () {
if(grav!=counter){
targetRotation=Quaternion.Euler(targetRotation.eulerAngles.x,targetRotation.eulerAngles.y,targetRotation.eulerAngles.z-90);
//targetRotation *= Quaternion.Euler(0,0,-90);
grav=counter;
}
switch(counter){
case 1:camera.main.GetComponent(Data).GlobalGravity = Camera.main.transform.right;
break;
case 2:camera.main.GetComponent(Data).GlobalGravity = Camera.main.transform.up;
break;
case 3:camera.main.GetComponent(Data).GlobalGravity = Camera.main.transform.right*-1;
break;
default:
camera.main.GetComponent(Data).GlobalGravity = Camera.main.transform.up*-1;
}
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime*2);
}
function OnCollisionEnter(collision : Collision){
if(collision.collider.tag == "Projectile"){
Instantiate(spark,collision.contacts[0].point,transform.rotation);
//if(counter<3){
counter++;
}
//}
}
Okay so the player shoots the arrow and changes gravity then rotates to point in the correct direction.Everything works fine except for the rotation part, which means I mark off the rotation code and shot it up and this glitch didn't happen. After two collisions the collider is set dramatically bigger to the side of the object.After 3 collisions the collider is stretched out diagonally across the whole stage(stupid invisible wall). I know it's the arrow collider because it's the only thing that makes sparks when you shoot it in the scene.When I pause the game to look at the collider it's a nice little capsule shape right where it should be. The arrow model(no collider) is a child of an empty game object with the collider component. The picture is a little misleading because the pivot point is in the center of the arrow instead of above it. I've use this code- targetRotation *= Quaternion.Euler(0,0,-90); , many times before with no problem, so please any help would be appreciated.