how to shoot the ball in the direction of the arrow ?
hi guys, please i want to know how to shoot the ball according to the arrow direction , the arrow ping pong in the z axis between 3 and -3
here is an image that illustrates the game please i need your help!
@Eric5h5 @tanoshimi @Bunny83 @robertbu @clunk47
Answer by tormentoarmagedoom · Feb 02, 2020 at 06:19 PM
Hello.
Firt learn, find, how to know the rotation of the arrow.
Then just apply a force, a velocity or translate the ball in the same rotation vector direction.
Answer by Tanoshimi2000 · Feb 02, 2020 at 09:55 PM
If the ball is in a GameObject (which it has to be) then use the forward value.
Ball.transform.forward.
here's some pseudo code to get you started:
public float forceAmount=5f; // Change this amount to increase/decrease the speed and distance the ball goes.
void Start(){
// Get the rigid body - this should be done in the Start()
Rigidbody rb = GetComponent<Rigidbody>();
}
void Update(){
if (Input.GetKey(kecode.Space)) ShootBall();
}
// Shoot the ball in the direction facing
void ShootBall(){
rb.addForce(transform.forward, forceAmount);
}
I just roughed this out, but it should get you started. Good luck!
thank you guys i got it i used an empty game object that rotate with the arrow then i set it as a start point
Your answer
![](https://koobas.hobune.stream/wayback/20220612222606im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Script creating 2 prefabs instead of 1 0 Answers
Problem with a shooting script. 0 Answers
Interesting Enemy AI issue 2 Answers
Don't know how to end animation of shooting ! (code) Please help ! 0 Answers
The bullet hole colliding with player and "Triggers" 0 Answers