How to move the position of the Z axis of my ship?

Hello I would like to know how to move the position of the Z axis of my ship?
I’m using:
transform.Translate(0,0,speed * Time.deltaTime);
But he did not throw in the position where my ship should point in front .

Please i am beginner and the examples I got did not help me .

image of my project

I think you’re asking: how can you make your ship move forward, no matter what direction your ship may be pointing?

But in that case, your code should already do it; Transform.Translate by default interprets the parameters relative to the object.

So maybe you want the opposite — you want to always move in the +Z direction, no matter which way your ship is facing? In that case, just add one more parameter:

   transform.Translate(0, 0, speed * Time.deltaTime, Space.World);

and this tells Unity that you’re trying to move it in world coordinates, rather than local coordinates.

transform.forward ought to do the trick?

No, he’s already translating forward. I think what he wants is to not translate forward, but to always translate in the +Z direction regardless of which way it’s facing. There are lots of ways to do that, of course; the one I showed above I think is the simplest fix for his current code, but if it were me, I’d probably just do:

transform.position += Vector3.forward * speed * Time.deltaTime;

which would accomplish the same thing.

Well , I just want to do my object which is actually the bullet my ship shoot in the direction where the spacecraft pointing .

the beak of the ship must shoot a bullet forward independent of the rotation of my ship .

and referring to your code I’ll take a look here .

Ah. The easiest way to do this is to first copy the transform from the ship into the bullet, and then move the bullet forward a bit (so it appears in front of the ship instead of in the middle of the ship). Something like:

GameObject bullet = bulletPrefab.Instantiate() as GameObject;
bullet.transform.position = transform.position;
bullet.transform.rotation = transform.rotation;
bullet.Translate(0, 0, 2);

That’s off the top of my head, and may contain errors, but it should be approximately correct.

code the direction of cloned projectiles .

#pragma strict
var speed : int = 10;

function Start () {   
}

function Update () {       
        transform.Translate(0, 0, speed * Time.deltaTime, Space.World);
        Destroy(gameObject,4);
   
}

the methods you told me he did shoot forward but only shoots forward , he still shoots where my ship is pointing , just follow where it goes but it does not shoot where you aim.

this is really weird cuz all the examples I got the scripts are the same thing and shoot .

code instantiation of missiles on the ship .

#pragma strict
var PTiro: GameObject; // Ptiro = prefap of bullet
function Start () {

}

function Update () {
    if (Input.GetKeyDown("space")){
        Tiro();
    }
}

function Tiro(){
    Instantiate(PTiro,transform.position,transform.rotation);
   
}

Sorry, I’m having trouble understanding you. Which is it that you want?

  1. The bullets go in the +Z direction, no matter which way the ship is facing. The ship could be pointing up, left, sideways, it doesn’t matter; the bullets always advance down +Z.

…OR…

  1. The bullets go in the direction the ship is facing. So if the ship is facing up, the bullets fly up; if the ship is facing to the left, the bullets fly to the left, etc.

Please specify which you’re trying to achieve, and then maybe we can help you make that happen!

  1. The bullets go in the direction the ship is facing.

currently my code like this :

#pragma strict
var PTiro: GameObject;
var speed : int = 10;
function Start () {

}

function Update () {
    if (Input.GetKeyDown("space")){
        Tiro();   
        transform.position += Vector3.forward * speed * Time.deltaTime;
    }
}

function Tiro(){
    Instantiate(PTiro,transform.position,transform.rotation);
}

Hello JoeStrout, posted shortly after I did the update of my Unity and done an update of Windows7 that I have until now a Feedback.
“Your 64 bit Windows installation is missing an important service pack patch. Please apply http://support.microsoft.com/kb/976038 to Ensure stability.”

But now the shot is running after you modify some things.

here is the code below:

#pragma strict
var speed : int = 10;
function Start () {   
}

function Update () {
        transform.Translate(0,0,speed * Time.deltaTime);
       
        Destroy(gameObject,4);
}

I have to apologize for the inconvenience, maybe I’ve confused me in the play scripts, since this code is to move the bullet. But do not know why with the other method did not work