Hello! I am trying to create a “jetpack” script that will move my object up and down. I dont have a character controler on my object as I will make a .move script later to move forward, back, left ,right etc. I do have a rigid body, mouselook script, and a constant force (all set to 0) on the object however. When I hold either left or right shift, errors will pop up about var target : GameObject, since im new to scripting I have no idea how to solve this problem and what class to use!!! Im trying to get a smooth effect to add a third dimension to movement of up and down. This is an edited script that Vicenti wrote the core of, I just edited it. Im useing unity 2.6 and cant upgrade as i have to remain compatible with an earlier game. Any and all help would be apreciated thanks!!!
This is the script
var boostFactor : float = 100; // or whatever
var target : GameObject;
function Update () {
if ( Input.GetKey(“left shift”) ) {
target.rigidbody.velocity += target.transform.up * boostFactor;
}
if ( Input.GetKey(“right shift”) ) {
target.rigidbody.velocity += target.transform.down * boostFactor;
}
}
That did fix the problem of unity not recognizing the target.transfrom.down. Thank you for the reply and help! Still does not work however and two new errors poped up
PPtr cast failed when dereferencing! Casting from Transform to GameObject!
UnityEngine.GameObject:get_rigidbody()
UnityEngine.GameObject:get_rigidbody()
jetpack:Update() (at Assets\jetpack.js:8)
[c:\builds\checkouts\branches\unity-2.6.x\runtime\baseclasses\BaseObject.h line 655]
and
MissingReferenceException: The variable target of ‘jetpack’ doesn’t exist anymore. This happened in the game object “Astro”.
You probably need to select the “Astro” in the hierarchy and reassign the target variable of the ‘jetpack’ script in the inspector.
jetpack.Update () (at Assets\jetpack.js:8)
“astro” is the object im attaching the scripts to, for all intents and purposes it is my “player character”
If you or anyone can help me with these errors then it SHOULD work, I think it is having issues with the target GameObject line because GameObjet always pops up in these and earlier errors.
and the target variable is astro in the inspector…
dude, Why do you have old varsion of Unity3D?
The current project that I am working on is a addon to an older game that was made entirely in 2.6 In order to seemlessly blend the two together, it is nessesary for me to work in the same version
Issue resolved, im using a modifyed flying script now instead of this, look at my other thread if you need help with this issue, it works for me