I have integrated an adjuster when picking up an object though it seems it's not working well. What I'm expecting is the values for z axis should be changing by 0.1f.
Some of the problems I'm facing:
- Initially i set the transform for x and y to 0. So only the z axis should be changing but in this scenario its different. All the axis keep on changing when adjusting the position holder.
- When adjusting the object moves in the x axis rather than in the z axis.
Here is the function which is supposed to handle that integration.
//adjust the position to move apparatus front or backwards
public void AdjustPositionHolder()
{
if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward
{
//increase the z axis to a certain position
pickupParent.transform.position = new Vector3(pickupParent.transform.position.x 0, pickupParent.transform.position.y 0, pickupParent.transform.position.z 0.1f);
//check the max z axis to adjust position
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards
{
//reduce the z axis
pickupParent.transform.position = new Vector3(pickupParent.transform.position.x 0, pickupParent.transform.position.y 0, pickupParent.transform.position.z - 0.1f);
//check the min z axis to adjust position
}
}
CodePudding user response:
to me, your code looks OK. Are you sure your object is moving on the x axis ? Depending on the rotation of your camera, you could get it wrong :/ Otherwise, if another component moves your object, it could be the issue here
Also, depending on your object hierarchy and what you want to do, you'll want to use localPosition instead of position ?