2D Toolkit Forum
2D Toolkit => Support => Topic started by: quangtu89 on August 23, 2013, 09:37:13 am
-
My script attach to tk2dcamera to drag camera axis x
public override void TouchDownOut (Vector2 position)
{
dragOrigin = new Vector3 (position.x, position.y, 0);
dragOrigin = camera.ScreenToWorldPoint(dragOrigin);
originTime = Time.time;
if(!isMove)
{
isMove = true;
}
}
public override void TouchMoveOut (Vector2 position)
{
Vector3 currentPos = new Vector3 (position.x, position.y, 0);
currentPos = camera.ScreenToWorldPoint(currentPos);
if(isMove)
{
if (Vector3.Distance(dragOrigin,currentPos) > 10f)
{
float amtToMove = 20f * Time.deltaTime;
LGController.state = LGController.State.Animation;
movePos = dragOrigin - currentPos;
movePos = new Vector3(movePos.x * amtToMove,movePos.y,movePos.z);
Vector3 newPos = transform.position + movePos;
newPos.y = this.transform.position.y;
transform.position = newPos;
}
}
}
public override void TouchUpOut (Vector2 position)
{
if(isMove)
{
isMove = false;
}
}
But it not smooth . Anyone help me ?
-
It tends to move a lot smoother if you move it in FixedUpdate. Its not obvious where you're calling this from. Also make it move by fixed amounts (i.e. chasing, but with a smooth function) to help smooth out the jerkiness.
-
i use this script
void FixedUpdate()
{
if(this.transform.position != targetPoint)
{
this.transform.position = Vector3.SmoothDamp(this.transform.position, targetPoint, ref unused, 0.15f, float.MaxValue, Time.deltaTime);
}
}
but i dont see move smooth
I think render sprite is trouble . I can see border in my sprite when camera move . I use sprite is a white square and i set color for its.
-
You should avoid moving the camera in sub-pixel positions if your textures aren't set up in a very specific way. If you're using 1 pixel per meter, then you can set position.x = Mathf.Round(position.x); to make sure its a pixel boundary.
You'll need a mirror Vector3 cameraPosition so you can still maintain the fragment position in FixedUpdate.