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)