Im making a ranger game where you shoot arrows at each other death match… But I cant make because i cant shoot the arrows going towards sky(i cant figure out) and also i need to be able to add force but when i fire arrow it either goes 1 direction or it doesnt go anywhere at all my codes going to be below this but i have an empty game object attacheted to this script so its not on the arrow itself… Thanks in advance
SHOOT SCRIPT :
var projectile :Rigidbody;
var speed = 20;
function Update () {
if ( Input.GetMouseButtonUp (0)) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * speed);
clone.rigidbody.AddForce(transform.position * 10);
}
}
You’re using AddForce wrong: you must pass a vector to AddForce, not a point - like this:
clone.rigidbody.AddForce(transform.forward * 10);
transform.position is a point: it defines a position in the space; a vector, on the other hand, defines a direction and isn’t tied to any particular position in the space. In this case, the vector defines the direction and its length defines the intensity of the force.
EDITED: Oops! I’ve just noticed that you’re setting the arrow velocity and also applying a force. Don’t do that: either set the velocity or apply the force - I personally prefer to set the velocity for arrows and other projectiles, like this:
if ( Input.GetMouseButtonUp (0)) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * speed);
}
An easier alternative:
if ( Input.GetMouseButtonUp (0)) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.forward * speed;
}