I’m creating a scene where I can grab parts for building a character and just as I finished how I want my camera set up I noticed something weird. The object I have grabbed when pulled towards the camera, splits in 2. Can anyone explain why its doing this or how to fix it?
Hey guys so I ended up solving this… It seems I am too persistent. I just ended up redoing my code (4 different ways) and got to this point. Here’s the code if you were interested. Just a reminder to anyone who uses this. This script is on each GameObject you want to move.
//Set for base starting distance (Will be changed using scrollwheel)
public float distanceWanted = 30f;
//While the mouse is held down
private void OnMouseDrag()
{
//For scrolling
float curCameraDistance = Input.GetAxis("Mouse ScrollWheel");
if (curCameraDistance > 0f)
{
distanceWanted++;
}
else if (curCameraDistance < 0f)
{
distanceWanted--;
}
Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceWanted);
Vector3 objPos = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = objPos;
}
not 100% sure this is happening but it looks like you are going over “0” with your movement, effectively your block is trying to move from 1 to -1 each frame because you keep moving it ‘towards’ the camera and overshooting the 0 mark. u might want add some boundaries to your script to stop this from happening, have the movement stop when ‘minDistance’ is reached.