- Home /
Rotation Problem
Here's the Script:
var CloneObject : Transform;
function Update () {
var Center = CenterObj.position;
if (Input.GetKey("right")){
transform.RotateAround(Center, Vector3.up, 25 * Time.deltaTime);
}
if (Input.GetKey("left")){
transform.RotateAround(Center, Vector3.up, -25 * Time.deltaTime);
}
if (Input.GetKey("up")){
transform.RotateAround(Center, Vector3.right, 25 * Time.deltaTime);
}
if (Input.GetKey("down")){
transform.RotateAround(Center, Vector3.right, -25 * Time.deltaTime);
}
Shoot(); }
function Shoot(){ var hit : RaycastHit; var rndRotate =transform.TransformDirection(Vector3(Random.Range(-0.1, 0.1), Random.Range(-0.1, 0.1), -1)); if(Physics.Raycast (transform.TransformPoint(0, 0.07, -1.2), rndRotate, hit, 200)){ Debug.DrawLine (transform.TransformPoint(0, 0.07, -1.2), hit.point, Color.green); var hitRotation = Quaternion.FromToRotation(Vector3(0, 1, 0), hit.normal);
var bullet : Transform;
bullet = Instantiate(Bullet, transform.TransformPoint(0, 0.07, -1.2), transform.localRotation);//InverseTransformDirection(0, 0, 1)
bullet.Rotate(rndRotate*70);
bullet.parent = CloneObject;
}
}
}
The Problem i am having is that when the gun rotates to the left, the bullets begin shooting downwards, and when i move it to the right, they begin shooting upwards.
Here's the script to move the bullets:
var BulletSpeed : int = 50;
function Start(){ rigidbody.AddRelativeForce(Vector3(0, 0, 1) * BulletSpeed); }
Anyone know why the Y rotation of my gun has somehow been changed to the X rotation of my bullets? Because the bullets shoot straight forward when the gun is straight forward, and only the X rotation of the bullets change when the Y rotation of the gun is changed.
Oh, Clone object is just there to hide all the clones in my hierarchy, its an empty gameobject.
Answer by FutchProductionsSyndicate · Jun 12, 2011 at 05:58 AM
I just did it without bones. It works now.
Your answer
Follow this Question
Related Questions
Instantiate not working 2 Answers
Shoot an object and have it move based on rotation 1 Answer
Have object face towards player when instantiated 2 Answers
Trouble Spawning Bullets with proper rotation 0 Answers
Instantiated Object looses prefab's rotation 10 Answers