- Home /
Question by
corax · Mar 25, 2012 at 04:22 PM ·
movementinterpolation
Movement interpolation
Hi guys,
I'm trying to create a 2d game, where a cube move towards a tap (using FingerGesture, amazing API :D). I've create the cube and the tap code, but the object jumps on spot instantaneously. Can figure out what I'm missing...
using UnityEngine;
public class LookAtTap : MonoBehaviour {
public float height = 0.5f;
public float velocity = 0.5f;
// reference to our tap gesture recognizer object
public TapGestureRecognizer tapRecognizer;
void Start()
{
// register to the tap recognizer's OnTap event
tapRecognizer.OnTap += tapRecognizer_OnTap;
}
// our tap event handler method
void tapRecognizer_OnTap( TapGestureRecognizer source )
{
rotateTarget(source.Position);
moveTarget(source.Position);
Debug.Log( "Source position " + source.Position);
}
void moveTarget(Vector2 MoveTarget)
{
Vector3 targetNewPosition;
targetNewPosition.x = MoveTarget.x;
targetNewPosition.y = height;
targetNewPosition.z = MoveTarget.y;
//movement interpolation
transform.position = Vector3.Lerp(transform.position, targetNewPosition, velocity) ;
Debug.Log( "Target position " + MoveTarget);
}
void rotateTarget(Vector2 Target)
{
Vector3 rotTarget;
rotTarget.x = Target.x;
rotTarget.y = 0;
rotTarget.z = Target.y;
var relativePos = rotTarget - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613065524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Networked position interpolation implementation (not Dead Reckoning)? 1 Answer
Network Trasnform Interpolation Factor 2 Answers
Network transform movement wont interpolate. How do i fix this? 0 Answers