- Home /
Define lerp axis through inspector
Hey guys,
Is it possible to define an axis for an object to lerp on in the inspector?
Can you explain yourself better? I might know the answer but I'm not quite sure what you want to achieve.
What i want to achieve is the following.
I have a script that animates gun parts. This script van be used for multiple guns, but the part of the different guns don't always have the same orientation for the xyz axis. Through the inspector i want to be able to define on which axis they have to lerp.
But a lerp in a 3D flat space has only one possible way to be done. From point A to point B the only possible path is the line from A to B. Do you mean you want to move only in one plane, even if that doesn't bring you from A to B?
For example: A = (0,0,0); B = (0,1,1);
You want to lerp en the xy plane so in the end: A = (0,1,0);
is this right?
The thing i do is this for one specific axis: slide.transform.localPosition.z = $$anonymous$$athf.Lerp(slide.transform.localPosition.z,-0.1,Time.deltaTime*10);
The thing i want is that i somehow dont need the localPosition.z anymore. Just one var or something
Answer by MrVerdoux · May 07, 2013 at 12:25 PM
Wow it looks to me that you are overthinking this, but maybe I'm wrong, let's see.
Why don't you use the lerp from Vector3 class? It may suit your purpouses better.
Otherwise, I think you are trying just to move a thing smoothly. Why don't you move it normally but you make the velocity itself to be lerped.
Another option is to make a class that can be set through the inspector and does this:
[System.SerializableAttribute]
public class Axis{
public enum AxisStateMachine{
Xaxis,
Yaxis,
Zaxis,
}
public AxisStateMachine axis;
}
Then you would be able to use this class in your weapon and make a more complex function that would take into acount the information of the axis to do as you want, and you would be able to set the axis through the inspector.
Hope it helps.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Enemy prefab's script won't keep inspector-applied settings. 0 Answers
Mathf.Lerp not working as expected 2 Answers
Lerping back and forth like a swipe page effect 0 Answers
Can I limit the rotation of an Object on an axis between a Negative and Positive value? 2 Answers