- Home /
Force For Arrows
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);
}
}
Answer by aldonaletto · Oct 12, 2013 at 12:37 AM
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;
}
the arrows arent moving no force they spawn then they have a rigid body so they fall no force added they dont fire like there soppsoed to and i tried both of your examples.....
Your answer
![](https://koobas.hobune.stream/wayback/20220613115755im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Create An Arrow With Unity3D 1 Answer
ragdoll force trouble 0 Answers