playMaker

Author Topic: [SOLVED] anyone see what's wrong with this code?  (Read 2229 times)

amaranth

  • Full Member
  • ***
  • Posts: 172
[SOLVED] anyone see what's wrong with this code?
« on: May 10, 2012, 08:00:57 PM »
I'm having a bit of trouble with this code. Here's a rundown: With this code, you drag the mouse anywhere in the scene to drag the camera. If you attempt to drag the camera on the x-axis past 0, the camera stops. All of this works if I use a very slow drag. If I use a fast drag, the camera moves past 0 into negative coordinates. This code is actually in a customized version of FingureGestures DragObject action.

I think I see the problem, but I'm not sure how to fix. If you use a large drag motion, this creates a large value for "move". So, if the camera's X-coordinate is larger than 0, and move is more than 0, the camera can move too far.

I tried using Clamp, but I wasn't sure how to transfer values between my camera and "move" since they seem to be using different coordinate systems. (camera = absolute position, move = distance to destination)

Code: [Select]
Vector3 currentFingerPos3d = ProjectOnCameraPlane( finger.Position, tf.position );
Vector3 previousFingerPos3d = ProjectOnCameraPlane( finger.PreviousPosition, tf.position );
Vector3 move = currentFingerPos3d - previousFingerPos3d;

// translate dragged object
if (objectIsCamera.Value)
{
// get the camera
var go = Fsm.GetOwnerDefaultTarget(objectToDrag);

// get the position of the camera
var cameraPosition = space == Space.World ? go.transform.position : go.transform.localPosition;

// if camera's x position is equal to or less than the camera's boundry, don't move the camera left
if (cameraPosition.x <= minCameraBoundry.Value.x)
{
// is player trying to move camera left? if yes, don't let them.
if (currentFingerPos3d.x > previousFingerPos3d.x)
         {
move.x = 0.0f;
}
}

// the specific amount to move the camera (move 25 px left, move 10 px right)
tf.position -= move;
}
« Last Edit: May 11, 2012, 04:48:07 PM by amaranth »

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: anyone see what's wrong with this code?
« Reply #1 on: May 11, 2012, 12:58:40 AM »
I fixed it, but I don't understand why it's better. By simply turning off an fsm on the camera and turning the fsm during runtime, the problem was fixed.