#Bullets nor moving

18 messages · Page 1 of 1 (latest)

burnt shale
#

Hello im working on the shooting part in my game the problem is thhat th bullets are spawning but not moving
Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

public class Shooting : NetworkBehaviour
{

private GameObject Bullet;
private Transform Firepoint;




void Start()
{
    Bullet = GetComponent<PlayerControll>().Bullet;
    Firepoint = GetComponent<PlayerControll>().Firepoint;
}




[Command]
public void CMDShoot()
{
    Shoot();
}




[ClientRpc]
private void Shoot()
{
    GameObject _Bullet = Instantiate(Bullet, Firepoint.transform.position, Firepoint.transform.rotation);
    _Bullet.GetComponent<Rigidbody2D>().AddForce(_Bullet.transform.forward * 1000);
}

}

river bane
#

You dont have a network transform on it right? (you should not)

#

Is your shooting script on player prefab?

burnt shale
burnt shale
river bane
river bane
#

AddForce needs to be applied over time (in fixed update)

#

not once in rpc 🙂

#

bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * activeWeapon.weaponSpeed;

this is what quickstart guide does

#

maybe use that but for 2d rigidbody (it does not need to be in FixedUpdate and can be once in rpc)

burnt shale
#

so should i use the velocity parameter now?

river bane
#

Its upto you, have a google to see what kind of bullet movement you want

#

But to summarise, AddForce needs to be in FixedUpdate, velocity can be once in Rpc - to create movement

burnt shale
#

i tried it with velocity and it doesnt work

burnt shale
#

Oh sorry i wrote transform.forward in a 2d game!