Search Unity

Calculate a float based on max and min values? Set float's max/min value rest calculated by Unity

Discussion in 'Scripting' started by zahovic3162, Jul 10, 2018.

  1. zahovic3162

    zahovic3162

    Joined:
    Jan 3, 2016
    Posts:
    41
    I will give the ratio Unity will handle the rest. float will be x in max and z in min in between will be calculated by Unity. What I need this for is on the photos. If you have a better idea please share. Basicly I will give a ratio to Unity and it will calculate when I change one of the values Unity_2018-07-11_01-28-04.png Unity_2018-07-11_01-28-10.png Unity_2018-07-11_01-28-18.png
     
  2. zahovic3162

    zahovic3162

    Joined:
    Jan 3, 2016
    Posts:
    41
    I will change the position of the gun when it is looking down and take the gun forward thus making it look propper but when it goes up gun needs to go back
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Are you asking about Mathf.Lerp() to interpolate between two floats?

    Or s this more of a rigging/animation question about the misrigged model above?
     
  4. zahovic3162

    zahovic3162

    Joined:
    Jan 3, 2016
    Posts:
    41
    I updated the post but what I want is I will give a ratio to Unity and it will calculate when I change one of the values. I will use it to fix that mismatching position of the weapon. Gun is attacked to an object and body is separated from it but hands are connected with IK but when I look up that objects need to move backwarsd to fix the problem and move forward when looking down and in between must be calculated based on those two values
     
  5. zahovic3162

    zahovic3162

    Joined:
    Jan 3, 2016
    Posts:
    41
    Hands will alwas on the right positions if the gun is in the range if it is too far the will simply move towards it as far as they can. So to fix the mismatching problem when I look up and down all I need it to move the gun to a propper position for boh cases
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,549
    If you want something to recalculate when you change the value, then use a C# Property instead, or assign the value using a method.

    Code (CSharp):
    1. private Vector3 somePosition;
    2. //Don't modify `somePosition` directly, but instead assign to `SomePosition`
    3. public Vector3 SomePosition
    4. {
    5.     set{
    6.     //Do something to the value when we set it.
    7.         somePosition = value;
    8.         somePosition.y = (somePosition.x + somePosition.z) / 2;
    9.     }
    10.     get{ return somePosition; }
    11. }
    Or if working with a transform

    Code (CSharp):
    1. public Vector3 Position
    2. {
    3.     set{
    4.     //Do something to the value when we set it.
    5.         value.y = (value.x + value.z) / 2;
    6.         transform.position = value;
    7.     }
    8.     get{ return transform.position; }
    9. }
     
  7. zahovic3162

    zahovic3162

    Joined:
    Jan 3, 2016
    Posts:
    41
    I decided to devide the value that changes when I look down and up then add or extract it from the y position. If this doesn't work I will try your method : D thanks for your help