Hello, this is a simple question, but how would I spawn an object at a certain velocity and position (relative to another object). Like a bullet firing from ship for a 2D shooter? Thanks.
Further to lampshade's answer, here is an example of how you can use instantiate and the sort of firing mechanism you may want to look into:
// make sure that the ammo is where it's supposed to be
GameObject ammoClone = (GameObject)Instantiate(ammo, startPointTransform.position);
// "firing" effect. The last parameter, ForceMode.VelocityChnage, is crucial in mimicking the initial velocity of a 'fired' object such as a cannonball or bullet.
ammoClone.rigidbody.AddRelativeForce(startPointTransform.forward * BlastForce, ForceMode.VelocityChange);
The above code, is a snippet. It assumes the following conditions:
- ammo is a reference to the object acting as the ammo.
- The ammo object has a rigidbody component attached to it.
- startPointTransform is a reference to the Transform of the object acting as the origin or start point of the ammo object
- BlastForce is a float which you could control to adjust the initial force applied to the ammo
To Bring something into existance? Instantiate! http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html