I decided to try this FPS Tutorial (http://download.unity3d.com/support/resources/files/FPS_Tutorial_1.pdf) to get into Unity and learn some things about it and Javascript, but I’m having trouble with something. When I went to fire the gun, it worked, but the projectile Instantiated what appeared to be a far ways from my gun. The script is here;
var projectile : Rigidbody;
var speed = 20;
function FixedUpdate()
{
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 );
}
}
If you have any suggestions, please tell me, I really want to learn Unity and Javascript, but I need to get past this point first.
Make sure that the object using that script is in the right position, because it’s instantiating the projectile at his same position and rotation.
It’s in the right position, no luck still. Any other suggestions?
Assume projectile is a prefab?
Check that its position is 0,0,0
not actually sure if this affects it, but just in case…
Can I bump posts on these forums?
I would use a helper object that is a child of your character to determine exactly where the projectile is spawned.
var projectilePosition:Transform;
...
var instantiatedProjectile:Rigidbody = Instantiate(projectile, projectilePosition.position, transform.rotation );
Also, you should be using Update(), not FixedUpdate(). Only code that affects physics directly should be done in FixedUpdate(). Technically you are spawning the projectile out of sync with what you see so that could account for some of the misalignment you’re seeing.
If it’s still not being spawned in the correct location the problem is probably with your prefab. Make sure the projectile’s local axis is exactly where you want it to be on the prefab.