When the script fires the bullet it goes to the wrong direction.
Bullet spawn script:
var input = new Vector3( Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical") );
transform.Translate(input * Time.deltaTime*moveSpeed, Space.World);
if (Input.GetButtonDown("Fire1"))
{
CmdFire();
}
// Disable physics for peer objects
GetComponent<Rigidbody>().isKinematic = !hasAuthority;
// Update player name
label.text = SteamFriends.GetFriendPersonaName(new CSteamID(steamId));
[Command]
public void CmdFire()
{
if (NetworkServer.active)
{
Transform spawnpos = transform.GetChild(1);
//spawnpos.rotation *= new Quaternion (spawnpos.rotation.x / 2, spawnpos.rotation.y / 2, spawnpos.rotation.z / 2, 1);
//spawnpos.position = spawnpos.position + new Vector3(1, 0, 1);
//double spawnpos2x = Convert.ToDouble(spawnpos.rotation.x);
/*float sinx = (float)Math.Sin(Convert.ToDouble(spawnpos.rotation.y));
float cosz = (float)Math.Cos(Convert.ToDouble(spawnpos.rotation.y));*/
Debug.Log(transform.forward);
var bullet = GameObject.Instantiate(bulletPrefab,
spawnpos.position,
spawnpos.rotation);
//spawnpos.position = spawnpos.position - new Vector3(1, 0, 1);
NetworkServer.Spawn(bullet);
bullet.GetComponent<Transform>().forward = transform.forward;
// bullet.GetComponent<Transform>().TransformDirection(transform.forward);
//bullet.GetComponent<NetworkTransform>().GetComponentInChildren<SphereCollider>().name = "Lovedek_" + SteamUser.GetSteamID().ToString();
Die dielet = GetComponent<Die>();
Debug.LogError(dielet.elet);
//dielet.elet = dielet.elet + 20;
//Debug.LogError(dielet.elet);
}
}
Move script:
void Update () {
transform.Translate(transform.forward * Time.deltaTime * speed);
}
Video: Bullet - YouTube