- Home /
bow and arrow game
i am making a simple bow and arrow game but i am currently facing some problems in giving a proper feel to how a arrow is actually fired.
i am trying to depict my problem with some images
this is what is happening right now
and this is what i want
basically what i want is to apply a heavy mass on the tip of the arrow so that when it falls it faces the tip of the arrow
I think your links broke down, i can't seem to select any. Or is "this" is what is happening right now just pointing at nothing?
Answer by AngryOldMan · Apr 28, 2011 at 02:11 PM
I've not actaully tried this but if I were to this is what I would try 1st.
import an arrow model to the game scene. make sure it has the right collider on. Then add two empty game objects to your scene. Move them into position over your arrow, one at the front one at the back then parent them to the arrow. Add a rigidbody component to each of the empty game objects. To the front one turn up its mass to suit and make sure uses gravity is checked. For the back one you will have to estimate how much mass it needs to have relative to the front one, not enough mass and the arrow will face straight down too early, too much mass and it wont tilt enough. i would then add a script to the arrow getting the rigidbody components of the parented empty game objects then applying a consistent gravity multiplied by its mass or turn the masses of the rigidbody to the same (both 10 or something) then apply different strengths of gravity to each one individually.
or on failing that I would add a rigidbody component to the arrow itself and add torque to it depending on how far it was going, so if it was going 360 feet in 1 second (impossible I know but just for simple maths sakes) it would turn (if it was being fired straight/ 90 degrees to the floor) between 10 and 20 degrees/second
Hmm, your idea is actually better then $$anonymous$$e I think. If you'd apply gravity to the front rigidbody but not the back one, the back one would simly follow the front one. Done.
Torque was the answer for my problem, as you proposed. Thanks!
Answer by Joshua · Apr 28, 2011 at 02:11 PM
You could either script the parabolic trajectory, which would be giving by a parabolic equation and constantly set the transform to this, or give the arrow more mass and set it's CenterOfMass to something like Vector3(0,1,0), and add in some drag.
Answer by Owen-Reynolds · Apr 28, 2011 at 02:54 PM
I use this to force projectiles to aim correctly, I'm pretty sure I'm not the first. The two lines in Update do the aiming (it's partial C# code):
bool dead; // uses so we can hang around for a while, after hitting public Transform hitFlash; // the PE when we hit something
void Start () { dead=false; }
void Update () { if(!dead) { Vector3 moveDir = transform.rigidbody.velocity; transform.LookAt(transform.position + moveDir); } }
void OnCollisionEnter(Collision cc) { if(dead) return; // just in case we try to double-die dead=true;
if(hitFlash!=null) Instantiate(hitFlash, transform.position, transform.rotation);
StartCoroutine(killMe()); }
IEnumerator killMe() { // stink in for a while, then drop through the ground: transform.collider.isTrigger = true; // no more collisions transform.collider.isKinematic = true; // freeze in place transform.rigidbody.freezeRotation = true; // not sure I need this transform.rigidbody.velocity = Vector3.zero; yield return new WaitForSeconds(3); transform.collider.isKinematic = false; // drop through ground yield return new WaitForSeconds(3); Destroy(gameObject); }
Answer by flaviusxvii · Apr 28, 2011 at 02:08 PM
"heavy mass on the tip of the arrow so that when it falls it faces the tip of the arrow"
But all masses fall at the same speed (not accounting for air resistance, which is key). What makes an arrow fly straight (and fall tip first) is the fletching at the back. You can give the fletching some air resistance by turning up Drag.
http://unity3d.com/support/documentation/Components/class-Rigidbody.html <-- Look at Drag.
$$anonymous$$asses all fal at the same speed in a vacuum. The rigidbody's drag coefficient uses the density of the object, however. So not changing the drag, but changing the mass, would work fine in this case. "The standard equation for drag is one half the coefficient of drag multiplied by the fluid mass density"
I'm just concerned that making the tip of the arrow overly massive (or inflating the effect of gravity) will have adverse effects. I've always found that making the most realistic approximation tends to give the best results (bereft of silly surprises). Adding drag to the back end would do this best.
Answer by elJoel · Apr 14, 2017 at 06:04 AM
I know this is old but I was looking for an answer for a long time so here's what I've finally used that worked pretty well: GameObject arrow = Instantiate(crossbowArrow, crossBowShotFrom.position, crossBowShotFrom.rotation); arrow.GetComponent ().AddForce(arrow.transform.forward * crossbowArrowSpeed, ForceMode.VelocityChange); arrow.GetComponent ().AddTorque( arrow.transform.forward * 10 );
Your answer
![](https://koobas.hobune.stream/wayback/20220613125925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My arrows penetrate walls 2 Answers
2D 360 degress platformer example needed 0 Answers
dynamic path arrows like in endless legends 0 Answers
Rotate towards velocity (2D) 2 Answers