Simulating the rise and fall of a crossbow bolt being fired

Hey all, here’s my situation: I want the player to be able to shoot a crossbow bolt and have the bolt object not just move forward along an axis (in my case, the x axis), but also trace an arc through the air like a real arrow would (taking into account how high up you aimed when you shot your arrow, how much force, etc…)

I have lots working so far including letting the player increase or decrease the angle and force one degree and/or unit per click of a corresponding GUI Button.

I can also fire the bolt using a “Fire” GUI Button on screen.

My problem is that even if I aim the bolt “up” so the tip is pointing up at 30 degrees, when I fire the bolt it just shoots straight forward along its x axis which looks pretty silly when your projectile is pointing up at 30 degrees!

I have gravity enabled and all that jazz, and I’ve searched for others with a similar problem but have found nothing pertinent (that I can tell).

How would I tell my program not to just shoot the bolt straight forward, but forward and UP if the bolt tip is aiming up at a certain angle?

And the second natural question, how would I tell the program to auto rotate the bolt tip to face down as the bolt starts to fall along the y axis due to gravity’s pull?

Thanks in advance for any help.

Are you using raycasts, because that wouldn’t be the way to go… I’ll assume you aren’t.

This is probably in the right direction:

``````var projectile : Rigidbody;
var speed = 20;

function Update () {
if (Input.GetButtonDown ("Fire1")) {
var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position,
transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0,0,speed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
}
}
``````

that should work, of course you’d need to add damage or whatever other things your using.

Hope that helped

As far as getting the arrow to rotate. I am thinking that an arrow is going to only be facing the direction it is traveling, at shooting speeds anyways, due to drag. So, you could probably do something like

``````function Update () {
rigidbody.rotation = Quaternion.LookRotation(rigidbody.velocity);
}
``````

with Freeze Rotation set on the rigidbody.

Thanks for the specific replies, guys.

I was not using raycasts, so you were right about that.

I’ll play around with these solutions and see which implementations fit the bill. Thanks again for your help!