FPS Tutorial Part 1- stuck on page 6 NEW POST.

Hello All,

Lately Ive been trying to learn how to shoot a Gun and am finally getting a little insight as to how its done, YAY!

Ok there’s always a but and here it is:

I found a Tutorial at:
http://unity3d.com/support/resources/tutorials/fps-tutorial-part1.html

And Im stuck at the bottom of Page 6 where it says:

-Now to associate the missile with the projectile variable in the script. Firstly, click on the Launcher in the Hierarchy Panel, notice the variable Projectile in the MissileLauncher script section in the Inspector Panel. All we need to do to associate the missile with this variable, is drag the Missile prefab from the Project Panel and drop it onto the Projectile variable.

The 1st problem Im having is, I can’t find the Projectile Variable in the MissileLauncher section in the Inspector Panel.

When I click on Laucher in the Hierarchy Panel all I see in the Inspector Panel is The MissileLauncher script.

The 2nd Problem I don’t know how to fix or what to do is, with the MissileLauncher script itself the Console or Debugger keeps popping up with a fault from my script that says:

Assets/WeaponScripts/MissileLaucher.js(13,46):BCE0018: The name ‘RigidBody’ does not denote a valid type. Did you mean ‘UnityEngine.Rigidbody’?

I don’t know what to do with this I tried replacing line 13 withUnityEngine.Rigidbody but that didn’t help.

Below I’ve pasted the MissileLauncher Script and Im also going to try and upload the project file for anyone willing to help me solve these issues or at least tell me what Im doing wrong but Im pretty sure I did everything step by step by the book.


var projectile : Rigidbody; // we declare projectile outside of any function to make it public, this exposes it to the Unity GUI
var speed = 20; //Also Exsposed to tweek below.

function Update () {
//Part-1, detects when the player hits the fire button
if (Input.GetButtonDown (“Fire1”)){

//Part-2, in Parenthases - the projectile is the object to instantiate, projectile is the object we want to create.

//transform.position - is the 3d position it should be created at. transform.position, creates the projectile at the same position as the launcher. Why the launcher? because this script wll be attached to the launcher.

//transform.rotation, this creates the missle with the same rotation properties as the launcher.
var instantiatedProjectile : RigidBody = Instantiate (projectile, transform.position, transform.rotation);

//Part-3, This part makes our missle move. Velocity is a property of instantiatedProjectile which is of type RigidBody (look at the API. Take a look at some of the other properties RigidBody has.

//To set the velocity we need to set the speed in each axis. However Objects in 3d are specified using two coordinate models: local and world

//local space = coordinates are relative to the object you are working with.
//world space = corrdinates are absolute, up is always the same direction for all objects.

//RigidBody.velocity must be pecified in world space. So when assigning the velocity, you need to convert it from the z-axis in local space to world space direction. You do this Using = transform.TransformDirection function which takes a Vector3 type as a parameter.
//The “speed” variable is also exposed above so we can tweek it in the GUI

instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0,0,speed));

//Part-4, This turns off collisions between the missle and the player. If we didn’t do this the missle would collide with the player when it was instantiated (fired). You can Look up “IgnoreCollision” in the API.
Physics.IgnoreCollision(instantiated.collider, transform.root.collider);

** } **
}


Boy I hope someone can help???

I attached a zip file of the unity scene where Im stuck. I can attach it as an other format if you prefer.

P.S. Sorry for all the commenting in the code its how I learn.

Sincerely,
Michael

92053–3623–$fps_151.zip (6.67 KB)

Can someone at least tell me why there is an issue with this line of code in the above post:
var instantiatedProjectile : RigidBody = Instantiate (projectile, transform.position, transform.rotation);

Unity’s Console error say’s:
Assets/WeaponScripts/MissileLaucher.js(13,46):BCE0018: The name ‘RigidBody’ does not denote a valid type. Did you mean ‘UnityEngine.Rigidbody’?

Also I just had a thought? I think it was something I read somewhere, Hear me out and tell me how far off I am, Here goes:

a Variable declared outside of a function() is a exposed variable that should appear in the Inspector View?

Does that sound correct?

And how do you declare a variable, just by putting var like:

var michael = some number value;
or
var michael : Ridigidbody

Thanks for hearing me out Im sure there will be more lol my brain is cooking overtime.

Sincerely,
Michael

var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);

small letter case b or small case letter b Rigidbody

Yep I had already changed The Capitol B in RigidBody to a lowercase b in Rigidbody and there is the same problem?

Any more suggestions?

Michael

Don’t understand why you’re getting that error, anyway try this simple packages I uploaded, it just shoots a sphere.

shoot.zip file has a shoot.unityPackage inside just import that in a project in your test project.

the script is nothing big just this

var projectile: Rigidbody;
var speed = 20;



function Update () 
{
	
	if(Input.GetButtonDown("Fire1") )
		{
			var instantiatedProjectile : Rigidbody = Instantiate(projectile,transform.position, transform.rotation);
			
			instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0,0,speed));
												
		}
		
				
}

Hope you fix the problem if not just continue asking. Someone here (the more experienced) will most likely help us both.

Ray

Ray,

Thank you sooo much for working on this with me it’s GREATLY APPRECIATED!

The Problem was the last line of code:

Physics.IgnoreCollision(instantiated.collider, transform.root.collider);

I ran your script “Fireourbullet” and deleted my “MissileLauncher” script and it worked fine (great actually!) I went through both scripts line by line letter by letter and thinking to myself they are both the same scratching my head then bingo a light went off, the above line of code causes the error.

I put the above line of code in your script and what do ya know the same error. Long story short…Thank You !!!

Its crazy that something so simple can set you back so much.

I do wonder why the it works without the IgnorCollision because the bullet dosen’t collide or affect the player?

There was another post on this same subject and they were stuck at the same exact place, time to let’em in on the secret…

Well Game On :slight_smile:

Sincerely,
Michael

P.S. Thank you ray for Taking the time!

Look at the scripting docs about Transform.root and Physics.IgnoreCollision

sometimes you need to use ignore collision depending on where you put the bullet/projectile.(if behind the GO or something or if you character has a over sized collider)

Ray