- Home /
Float not Multiplying
So all this script is doing is detecting the relative speed of movement and rotation of an object and then combining those to output a float to another game object. when I multiply the variable heightDifference it works as expected, but for some reason, rotDiff does not change. the output I'm getting for heightDifference is between .01 and .04 and for rotDiff are between -9 and 10. not only will the number not multiply (I have tried breaking it out into many steps) but it's not impacting the final output of speedMultiplier.
Have I just missed something super silly?
![using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MagnitudeToSpeed : MonoBehaviour
{
public float speedMultiplier;
public Vector3 startingPos;
public Vector3 startingRot;
public float heightDifference;
public float rotDiff;
// Start is called before the first frame update
void Start()
{
startingPos = transform.position;
startingRot = transform.localEulerAngles;
}
// Update is called once per frame
void Update()
{
rotDiff = transform.localEulerAngles.x - startingRot.x;
heightDifference = transform.position.x - startingPos.x;
speedMultiplier = 1 + (Mathf.Abs(heightDifference) * 100) + (Mathf.Abs(rotDiff) * 100);
startingPos = transform.position;
startingRot = transform.localEulerAngles;
}
}][1]
[1]: /storage/temp/149492-screenshot-137.png
Answer by lgarczyn · Dec 03, 2019 at 03:13 AM
Add 'Debug.Log' to every variable (startingRot, transform.localEulerAngles and rotDiff) every update.
This could be because you are using x instead of the axis you are actually rotating, because the transform made a full turn, or because you are rotating the parent of the object instead of the object.
Please note that your title is absolutely not descriptive of your problem. Something like "local euler angles not changing on rotation" would be better.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215616im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Float to db 2 Answers
Bad result on a rest between 2 floats 1 Answer
Float subtracting in increments of 1 no matter what value it's subtracted by 0 Answers
Is it possible to round down 0.99 to 0? 2 Answers
how to keep fraction number ??? 1 Answer