6 Replies - 613 Views - Last Post: 19 June 2013 - 08:59 PM Rate Topic: -----

#1 AdoTheLimey  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 78
  • Joined: 28-June 10

[Unity]Tweening is not consistent

Posted 04 June 2013 - 04:55 PM

I need to move my camera a fixed distance over a fixed amount of time, depening on what key is pressed. I've tried to accomplish this with both iTween and LeanTween, with the same wonky results, so the issue has to be my code. It's working mostly as intended, but half of the time the tweening does not take place - my camera immediately snaps to the new location instead of smoothly moving to the target. Below is my update method and one of my movement methods. Should tweening be handled in Update or FixedUpdate? Any ideas why the tweening is only happening some of the time?

Video to show problem in action: http://www.youtube.c...h?v=dZcgapCyDOU

void Update ()	
	{	
		if(firstrun)
		{
			playerMarker = explorationCameraController.explorationCamera.transform.position;
			firstrun = false;
		}		
		
		if(explorationCameraController.explorationCamera.transform.position == playerMarker)
		{			
			if(Input.GetButtonDown("Forward"))
			{						
				MoveForward(explorationCameraController.CurrentDirection);
			}
			
			if(Input.GetButtonDown("TurnRight"))
			{
				TurnRight(explorationCameraController.CurrentDirection);
			}
			
			if(Input.GetButtonDown("TurnLeft"))
			{
				TurnLeft(explorationCameraController.CurrentDirection);
			}
			
			if(Input.GetButtonDown("Backward"))
			{
				MoveBackward(explorationCameraController.CurrentDirection);
			}
			
			if(Input.GetButtonDown("StepLeft"))
			{
				StepLeft(explorationCameraController.CurrentDirection);
			}
			
			if(Input.GetButtonDown("StepRight"))
			{
				StepRight(explorationCameraController.CurrentDirection);
			}
		}		
	}
	
	public void MoveForward(string CurrentDirection)
	{
		switch (CurrentDirection.ToLower()) 
			{
			case "up":
			default:
			{				
				Vector3 direction = new Vector3(0,0,1);				
				if(!isWall(direction))
				{
					playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
					LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);	
					//iTween.MoveTo(explorationCameraController.explorationCamera, new Hashtable(){{"position", playerMarker},{"time", moveSpeed}});
				}
				break;
				
			}
			case "right":
			{
				Vector3 direction = new Vector3(1,0,0);				
				if(!isWall(direction))
				{
					playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
					LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
				}
				break;
			}
			case "down":
			{
				Vector3 direction = new Vector3(0,0,-1);				
				if(!isWall(direction))
			{
					playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
					LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
			}
				break;
			}
			case "left":
			{
				Vector3 direction = new Vector3(-1,0,0);				
				if(!isWall(direction))
				{
					playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
					LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
				}
				break;
			}
			}
	}


This post has been edited by AdoTheLimey: 04 June 2013 - 05:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [Unity]Tweening is not consistent

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: [Unity]Tweening is not consistent

Posted 04 June 2013 - 05:31 PM

1. Are you on powerful enough system to run this code?
2. How many times is the scene updated per second?
3. What is the draw distance?
4. How do you know there are no errors in your calculations? You need to be able to debug to find out for sure.

Just some things to think about.
Was This Post Helpful? 0
  • +
  • -

#3 AdoTheLimey  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 78
  • Joined: 28-June 10

Re: [Unity]Tweening is not consistent

Posted 04 June 2013 - 07:14 PM

Thanks for the reply. My responses:

1. I would think so. All it's doing is rendering around 50 cubes and moving a camera object among them. I also built the project to eliminate any overhead from the editor, but I had the same result.
2. I believe it's 60 times a second.
3. Near clip is 0.3f, far clip is 100f.
4. I dont think its a problem with the calculations. Without the tweening, the camera will correctly snap to the new position when a movement key is pressed. I'm passing the current camera position as the start point and the calculated new position as the destination for it to tween to. The camera will end up at the correct location every time, but its the actual tween itself that seems to get skipped about 50% of the time.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: [Unity]Tweening is not consistent

Posted 05 June 2013 - 03:00 AM

Okay. Regarding the number of frames you need to be sure. Your answers are too vague which is exactly the same as not knowing.

I would still check the logic of your tweening as well as whether your resources are being loaded quickly enough to render the walls that pop into the scene.
Was This Post Helpful? 0
  • +
  • -

#5 AdoTheLimey  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 78
  • Joined: 28-June 10

Re: [Unity]Tweening is not consistent

Posted 19 June 2013 - 07:18 PM

Finally got this figured out. I was adding the direction to the player position instead of just my camera.

http://www.youtube.c...h?v=s_Xf6EeiK_4
Was This Post Helpful? 1
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: [Unity]Tweening is not consistent

Posted 19 June 2013 - 08:29 PM

You're still getting odd rendering going on though - your walls are breaking up.
Was This Post Helpful? 0
  • +
  • -

#7 AdoTheLimey  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 78
  • Joined: 28-June 10

Re: [Unity]Tweening is not consistent

Posted 19 June 2013 - 08:59 PM

That's just the compression in the video.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1