So I tried to make jump with DG.Tweening but he player always jumps back to the first nextPos and then to the place where he should in the first place.,
Video about how it looks: https://drive.google.com/open?id=12yUAX6wB1hsTmCSDS01RIuRV_vFflWH7
public class Movement : MonoBehaviour
{
Vector3 up = Vector3.zero, right = new Vector3(0, 90, 0), left = new Vector3(0, 270, 0), down = new Vector3(0, 180, 0), currentDirection = Vector3.zero; float jumpPower = 1.3f; float jumpTime = 1f;
Vector3 nextPos, destination, direction;
float speed = 5f;
bool canMove;
float rayLenght = 1f;
void Start()
{
currentDirection = up;
nextPos = Vector3.forward;
destination = transform.position;
}
void Update()
{
Move();
}
void Move()
{
float desiredRot = 0;
transform.position = Vector3.MoveTowards(transform.position, destination, speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.W))
{
nextPos = Vector3.forward;
currentDirection = up;
canMove = true;
desiredRot = 0;
//JumpUp();
}
if (Input.GetKeyDown(KeyCode.S))
{
nextPos = Vector3.back;
currentDirection = down;
canMove = true;
desiredRot = 180f;
//JumpUp();
}
if (Input.GetKeyDown(KeyCode.D))
{
nextPos = Vector3.right;
currentDirection = right;
canMove = true;
desiredRot = 90f;
JumpUp();
}
if (Input.GetKeyDown(KeyCode.A))
{
nextPos = Vector3.left;
currentDirection = left;
canMove = true;
desiredRot = -90f;
JumpUp();
}
void JumpUp()
{
transform.DOLocalJump(nextPos, jumpPower, 1, jumpTime).OnComplete(() => {
});
transform.DORotate(Vector3.up * desiredRot, jumpTime);
}
if (Vector3.Distance(destination, transform.position) <= 0.00001f)
{
transform.localEulerAngles = currentDirection;
if (canMove)
{
if (Valid())
{
destination = transform.position + nextPos;
direction = nextPos;
canMove = false;
}
}
}
,
Comment
Your answer
Follow this Question
Related Questions
Detect if velocity equals 0? 2 Answers
[2D Platform Game] Precise Jumping Without Holding Down Directional Button. 0 Answers
Error CS0120 : An object reference is required to access non-static member 3 Answers
Navmesh interfering with mecanim jump animation (root motion) 1 Answer
Player looses ability to jump further right player moves. 1 Answer