- Home /
Arm Look At script Issues (javascript)
I want to have a script that when I set weaponReady to true that the arms will aim to the center of the screen (the lookTarget game object). Unfortunately, I get this:
"NullReferenceException: Object reference not set to an instance of an object" @ line 13
What do I do if my script goes with no errors yet my arms won't rotate during the animation?
var lookTarget : GameObject; var leftArm : GameObject; var rightArm : GameObject; var player : GameObject; @HideInInspector var lookRotate : float; var boneControl : GameObject;
function Update () { if (player.GetComponent(PlayerMovement).weaponReady == true) {
lookRotate = boneControl.transform.rotate.y.LookAt(lookTarget);leftArm.transform.rotate = lookRotate; rightArm.transform.rotate = lookRotate; } }
Answer by tanoshimi · Jan 02, 2015 at 05:11 PM
lookRotate = boneControl.transform.rotate.y.LookAt(lookTarget);
that line is just weird. rotate
is not a member of transform. You might have meant rotation
but, if you did, you wouldn't then be able to call the LookAt() method of a float variable (y).
Given that you're asking about LookAt, which is a function of the Transform component, did you mean:
leftArm.transform.LookAt(lookTarget);
rightArm.transform.LookAt(lookTarget);
?
Now I get "Assets/Scripts/Control/ArmControl.js(11,42): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.GameObject)' was found." For both lines.
Also I have an appropriate pose for holding the gun. I just want my arms to move up and down ai$$anonymous$$g towards the center of the screen without messing up the animation for the arms.
Updated Script: var lookTarget : Transform; var cameraObject : GameObject; var leftBone : GameObject; var rightBone : GameObject; var armControl : GameObject; @HideInInspector var currentX : float;
function Update ()
{
currentX = armControl.transform.rotation.x + cameraObject.GetComponent($$anonymous$$ouseLook).currentXRotation;
}
function LateUpdate ()
{
if(GameObject.FindGameObjectWithTag("Player").GetComponent(Player$$anonymous$$ovement).weaponReady == true)
{
armControl.transform.LookAt(lookTarget);
leftBone.transform.rotate = Quaternion.Euler(currentX, 0, 0);
rightBone.transform.rotate = Quaternion.Euler(currentX, 0, 0);
}
}
Getting this error: $$anonymous$$issingFieldException: UnityEngine.Transform.rotate Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter () Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey19.<>m_F () Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.Dispatcher$$anonymous$$ey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) ArmControl.LateUpdate () (at Assets/Scripts/Control/ArmControl.js:20)
Your answer
Follow this Question
Related Questions
hoe to rotate a AI as a animation 1 Answer
LookAt Problem 1 Answer
Rotating Toward an Object at a Constant Speed 2 Answers
Help with plat-former character rotate 1 Answer
Look At objects using a SNAPPED angle 2 Answers