My cannon is shooting balls whenever FireCannon() function is called by creating a clone of cannonBall. I want to find the velocity of every cloned ball which is being fired & display it as text. I have tried to write a code which is displaying the velocity of the last cannonBall(cloned) fired but I am pretty sure this is not the right velocity.
Can anyone help !!
I am a beginner.
public void FireCannon()
{
GameObject cannonBallCopy = Instantiate(cannonBall, shotPos.position, transform.rotation) as GameObject;
cannonballRB = cannonBallCopy.GetComponent();
cannonballRB.AddForce(transform.forward * BlastPower);
Instantiate(shotPos, shotPos.position, shotPos.rotation);
speed = Mathf.RoundToInt(Vector3.Distance(shotPos.position, shotPos.localScale) / Time.fixedDeltaTime);
gameText.text = "Speed of ball: " + speed + "m/s";
}
↧