How to create arrow to throw ball with arrow's direction

Hi,

I want to throw ball to bounce in a room. I use this script to throw ball:

#pragma strict

var ball : GameObject;
var speed : float = 700f;
var isBallThrowed = false;

function Start () {

	}

function Update () {
	if(isBallThrowed == false) {
		if(Input.GetKey(KeyCode.Space)) {
			isBallThrowed = true;
			ball.rigidbody.AddForce(129f,0,speed);
			ball.rigidbody.useGravity = true;
		}
	}
}

Throwing is OK, but I don’t know how to set up direction of throwing in the game.
I think, from the ball is needed to create arrow and player may with arrow keys change ball’s throw direction.
I use Unity only from start working on this project, so I will be grateful for any advice.

Thanks :slight_smile:

you can rotate the ball to face the direction you want to shoot and then instead of addforce use addreletiveforce

That sounds great, but will player see where is ball facing? I think something like arrow, that will be pointing from ball. When I press right key, this arrows rotate to right and when a I throw ball, it will be thrown to this, changed direction.

well there isn’t a “show arrow” command, you would have to make an arrow.

what you can do is child the ball to your arrow game object and make sure they start off facing the same way, then rotate the arrow and the ball will follow the rotation, then when you want to shoot the ball, unparent it from the arrow and add for relative force

I can rotate ball before throwing with this script:

if(Input.GetKey("up")) {
    ball.transform.Rotate(-1, 0, 0);	
}

and next directions similar to this. When I throw it, it is moving with right direction.

But when i create object (for example cylinder), i dont know how to rotate it around ball’s pivot point for a graphical representation of the direction of the throw. Cylinder is still rotating around own center pivot :frowning:

look up rotatearound in the script reference, this should let you rotate around another point in the world