- Home /
Question by
unity_0979C3629A29CFCD264B · Dec 27, 2021 at 06:19 PM ·
velocityballclone
How can I display Cloned ball velocity in text ?
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<Rigidbody>();
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";
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051002im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to Instantiate and change velocity 2 Answers
How to set ball velocity after it was hit with a racket in a tennis game? 0 Answers
Random ball generator? 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
[SOLVED] 3D Ball in Breakout clone acts unpredictably when colliding with corners 1 Answer