I'm currently using myRigidBody.AddForce(x,y,z) to move an object. I'm guessing that the three values in AddForce are in Newtons(kg m/s^2) I'm not sure. I've been asked to change the program to launch the projectile with and angle and initial velocity. I have not yet found anything in the scripting documentation that specifically mentions using angle and velocity and I don't know a way to work backwards from initial velocity and angle to get three vectors of force.
The X,Y,Z values represent a Vector, whose direction is the angle, and whose length is the velocity. However the AddForce function has another version which accepts a vector explicitly rather than having a parameter for each of the x,y & z values.
In addition, if you're applying a force which is the equivalent of a single push at an instant in time (rather than a push over a duration of time), you should use a special force mode called "Impulse".
You can apply a force in the direction of a particular gameobject by using that gameobject's transform.forward property. For example, to launch a projectile in the direction of the gameobject on which the script is placed, you could use something like this:
using UnityEngine;
public class FireTest : MonoBehaviour {
public Transform bulletPrefab;
public float shotPower = 80;
void Start()
{
// wait 10 secs, then fire every 5 seconds
InvokeRepeating("Fire", 10, 5);
}
void Fire () {
// the starting conditions (the position and angle of the 'gun' object)
Vector3 startPos = transform.position;
Quaternion shotAngle = transform.rotation;
// create the projectile object
Transform bullet = (Transform)Instantiate(bulletPrefab, startPos, shotAngle);
// apply the firing force
bullet.rigidbody.AddForce(transform.forward * shotPower, ForceMode.Impulse);
}
}
well if you have the velocity that have its magnitud, and you have an angle you can transform that in a vector this means for trigonometry that velocity*sin(angle) will give you the velocity vector in the y axis and velocity*cos(angle) will give you the velocity vector in the x axis. i'm also using the force in unity to move the objects, but now i see that the velocity would be easier for the future use, so im changin to that =P
good luck