- Home /
Floats not being applied?
I'm very close on completing a script that allows the arms of my character to aim towards the camera. I used the last spine bone to apply the rotations to.
And here's the problem:
This is my hold animation with the chest slightly turned.
With script enabled:
The spine bone I assigned as the bone to rotate is instead facing the direction of the camera at all times. This offsets the position of the arms to the left.
I calculated the float value difference (x and y rotations) between the camera(or head/neck) and the spine bone when the animation is correctly displayed (script disabled) and I added it to my ArmControl script. Unfortunately, adding those float values are not making a difference when the script is enabled.
ArmControl (JavaScript):
var spineBone : GameObject;
var cameraObject : GameObject;
var mountObject : GameObject;
var spineX : float = 2.683764;
var spineY : float = 5.290291;
var spineXPose : float;
var spineYPose : float;
function LateUpdate ()
{
if(GameObject.FindGameObjectWithTag("Player").GetComponent(PlayerMovement).weaponReady == true)
{
spineXPose = mountObject.GetComponent(MouseLook).currentXRotation + spineX;
spineYPose = mountObject.GetComponent(MouseLook).currentYRotation + spineY;
spineBone.transform.rotation = Quaternion.Euler(spineXPose, spineYPose, 0);
}
}
I'm also including my camera control script to help out with specific components I'm using:
var lookSensitivity : float = 5;
@HideInInspector
var yRotation : float;
@HideInInspector
var xRotation : float;
@HideInInspector
var currentYRotation : float;
@HideInInspector
var currentXRotation : float;
@HideInInspector
var yRotationV : float;
@HideInInspector
var xRotationV : float;
var lookSmoothDamp : float = 0.1;
function Update()
{
yRotation += Input.GetAxis("Mouse X")*lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y")*lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -20, 35);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation,0);
}
Answer by CyberArtist · Jan 04, 2015 at 03:54 PM
Turns out the value of my calculations were too small.
If you want to see the end result of trying to make this script work, check out the post I made in the forums: http://forum.unity3d.com/threads/rotation-missingfieldexception-error.288798/
Your answer
![](https://koobas.hobune.stream/wayback/20220613175544im_/https://answers.unity.com/themes/thub/images/avi.jpg)