My bullet shoots sideways, help!?

here’s the script, can someone point out why my bullet shoots sideways instead of straight?

cheers

var Bullet : Transform;
var Spawn : Transform;
var BulletSpeed = 100;

function Update ()
{
if(Input.GetButtonDown(“Fire1”)){
Fire();
}
}

function Fire()
{
var Bullet = Instantiate(Bullet,Spawn.position,Spawn.rotation);

Bullet.rigidbody.AddForce(transform.forward * BulletSpeed);

}

Is there a OnPhotonPlayerConnectedToRoom() ?

2 Answers

2

try

Bullet.rigidbody.AddForce(spawn.forward * BulletSpeed);

spawn.forward will be the blue axis of the spawn.

transform.forward is the blue axis of whatever object this script is attached to, but doesn’t give the desired effect because your model is probably rotated.

make it local coordinates and not world coordinates in the inspector, I think that's important

Thanks man! and yes, the model of my gun has been rotated very much.

You're welcome! If my answer helped you, please click the check-mark on the left of it. :)

Oh, sorry haha, didn't know i had to :)

Why dont u try something except forward like sidewalk(i mean u probbably want to shoot in X axis not Z) or sth i myself usually call this function like this:
Bullet.rigidbody.AddForce(BulletSpeed,0,0);

/AddForce(x,y,z) look in which direction u want to shoot it maybe your objects are in way that u need to shoot them in x Axis(red one) or in some 2D games u may want to shoot them up!/

OnJoinedRoom(); I'm not sure if that's what your looking for, but it happens when the client connects to a room.