I couldn’t figure it out with my inadeuqute physics knowledge.
I am firing an arrow with a certain speed to a specific target. I know my position, target position, speed of the projectile and the angular rotation of the projectile. With those, I am trying to find the starting angle of the projectile to reach the destination.
It is a simple projectile motion problem but the projectile motion equation is not interested of the angular rotation, it is calculation according to the gravity so this equation is not worknig for me:
Hey bud. I think you could simplify your problem and use a rigidbody.
If you take this script and add it to your camera or a parent gameobject of your camera.
and add a prefab of your arrow to it in the inspector.
MOST IMPORTANTLY, YOUR ARROW GAMEOBJECT SHOULD HAVE A RIGIDBODY COMPONENT ADDED TO IT.
Sorry for shouting lol
Gruffy
Code below:
using UnityEngine;
using System.Collections;
public class Shooter : MonoBehaviour
{
GameObject currentCol;
//declare and init shooter vars
public Rigidbody bullet; //add a prefab(arrow) MAKE SURE THE ARROW HAS RIGIDBODY COMPONENT ATTACHED TO IT
public float power = 1500f; //forward power
// Update is called once per frame
void Update ()
{
if(Input.GetButtonUp("Fire1"))
{
//instantiate projectile - (overloads) what ?, where ?, a rotation ?
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
//vector to represent forward direction of the current transform
Vector3 fwd = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd * power);
//Physics.IgnoreCollision (transform.root.collider, bullet.collider, true);
//audio.PlayOneShot(bulletAudio);
}
}
}