- Home /
Problem when creating a projectile for a weapon. (FIXED)
Hi I'm having a problem with a projectile for my First Person Character Controller, when I press the fire button it spawns but it is rotated facing a different direction instead of straight forward, does anyone know what is wrong?
Here's a Video of my problem. http://www.youtube.com/watch?v=g632TdDKuCw
Here's my code.
var projectile : Rigidbody; var speed = 10;
function Update() {
if( Input.GetButtonDown( "Fire1" ) ) {
audio.Play(); // Delay a clip by 1 sec (44100 samples) audio.Play(44100);
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation ); instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) ); Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider ); } }
The rotation of the Bullet is Rotation X0 Y90 Z0 Y was originally 0 but I changed it, it still no improvement. Also could the problem be this? transform.rotation );
Can anyone help me? Fixed the problem, using different model.
Dryden Richardson, when you have a problem like this is better to put your script ins$$anonymous$$d of a video, unless the problem is in physics or something like that.
Like Uriel Said perhaps if you where to post the code where you create the projectile we would be able to help you a bit more. It sounds like you might have a problem in you Instantiate call though, obviously I'm not sure how your handling the projectiles but I found it works best if you make a prefab and instantiate it with the players rotation. You may also want to check the axises of the projectile to see if perhaps it is instantiating the proper way but you should be using the x ins$$anonymous$$d of z or vice versa. Hope that helps a little bit. If you post your code I'll be more help.
Answer by Joshua · Aug 15, 2011 at 02:18 AM
You're probably using Instantiate to spawn the projectile. The third parameter of this method is the rotation. Change to rotation to what you want it to be.. most likely the transform.forward of the character.
That's 'a' rotation. But I don't know how the axis are set up for your model. It could be that for 'forward axis' is pointing sideways.
Okay here's the axis Rotation X0 Y90 Z0 The Y Axis was originally 0 aswell but I change it and there was still no improvement.