How to rotate an object
I have a problem with a script. I am making a FPS Game and i have a spawn bullet script. It's pretty simple, but it does what it was supposed to do. At least most of it...
I want to spawn a cilinder and then make it go, you know, like "fly, you are free". I am glad that everything works fine, except that it's pretty unconfortable to see your bullet fly inverted =|
When it spawn, it is inverted. Not that it goes backward, but it is pointed up, when it was supposed to be pointed to the sides. The image explains everything.
Here's my script:
using UnityEngine;
using System.Collections;
public class ShootTime : MonoBehaviour {
public Rigidbody projectile;
public float speed = 0;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
void Update()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Rigidbody clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
}
}
}
What can i do to change the bullet so it spawn like... A BULLET. And still nothing changes in it's aerodynamics/direction?
Answer by TheShadyColombian · Aug 09, 2016 at 05:51 PM
Recreate your prefab as an empty, which has your 3D model as a child. Rotate the child (the 3D model), not the parent (the empty), how you want, and then use a prefab of the whole thing as your bullet.
Have you actually read the script? It requires a GameObject with physics. Did you know that? I don't think i will be able to throw an empty game object at it, and change the script would take time that i don't have =/
so keep all physics components (rigidbody, collider) on the empty, and all graphic components (mesh, $$anonymous$$eshRenderer) in the child object.
Still, i don't believe it will work, but i will give it a try.
Answer by sambid123sameer · Aug 09, 2016 at 06:56 PM
I guess you are using a prefab for the bullet?
Take the prefab in the scene and make sure the Blue arrow (Z Axis) is pointing the correct direction and rotation you want the bullet to go
Example something like this :-
if not then you have to make a new bullet with the blue (Z Axis) pointing correct direction
Im saying 'Z' here because in your script , in the vector3(X,Y,Z) you have set the speed variable on the Z position (0,0,speed) which is X=0 , Y=0 , Z = Speed variable
P.S Sorry for my noob explanation :P
I know that, it's correct. It doesn't change anything.
it should work lol
can i see your bullet prefab? drag it into the scene and letme see it