How can I apply a position (and not a translation) to my camera related to an axis value
Hello,
I've been trying a lot of different ways to do this, reading the docs and tutorials and I still didn't managed it. I want my camera to move according to a joystick position, between UP (=1) and down (=1). But I don't want it to be translated according to the joystick value (althought that's what I get). I want the camera to move only when the joystick value changes.
When the joystick is =+1, the camera should be at a maximum position along Z axis. If the joysticks stays UP (=1), the camera should stay at this position. If the joysticks then gets 75% UP (=0,75), then the camera should go BACKWARDS to move to a position representing 75% of the distance between the initial position and the maximum position.
I don't know if you will get what my I mean.
Here is my actual code :
public Vector3 Campositionworldinit;
public Vector3 Campositionlocalinit;
public Vector3 Campositionworldtarget;
public Vector3 Campositionlocaltarget;
public Vector3 Campositionlocaltarget2;
public Vector3 Campositionworldactual;
void Start()
{
Campositionworldinit = transform.position;
Campositionlocalinit = transform.InverseTransformPoint(Campositionworldinit);
}
void Update()
{
Campositionworldactual = transform.position;
Campositionlocaltarget = Campositionlocalinit;
Campositionlocaltarget.z = Input.GetAxis("Joystick1X");
Campositionlocaltarget2.z = Campositionlocaltarget.z - Campositionlocalinit.z;
Campositionworldtarget = transform.TransformPoint(Campositionlocaltarget2);
print("Campositionlocaltarget2.z" + Campositionlocaltarget2.z);
transform.position = Campositionworldtarget;
}
}
Another weird thing ; when my joystick is on neutral position (=0), there is no printing for Campositionlocaltarget2.z is the console (which should be = 0). Only preceding values. Why ?
Thank you very much for your kind help.
Your answer
Follow this Question
Related Questions
hi all im trying to add fire stick to my shooter.. 0 Answers
Get camera position back to starting position 0 Answers
Joystick 3rd Axis problem on Linux 0 Answers
X360 Controller detection gives uneven quadrants 0 Answers
How to make an object move in the direction another object is facing on 2 axis? 1 Answer