Hello all,
I am making a 2D action/beat-em-up game and having a bit of trouble with the air movement scripts. I already have all the appropriate physics systems in place to ensure gravity, jumping etc.
Right now, I am attempting to make an air dragon-kick type move that will propel the player forward by a set amount while killing all enemies he passes through. The input for this move is: Direction you want to kick (left or right) + heavy attack button.
Let me very very clear about this: I am not having trouble making him move. I am having trouble making him stop at the right place. I only want him to move a certain amount of units away from his starting position. As an example, let’s say 5 ft or something. He should only fly forward 5 ft worth of Vector units and STOP.
I’ve used Rigidbody.velocity to move stuff a fair bit. But I don’t want to mess with it in this case, as there are already a bunch of things in the game that alter your velocity. I want to keep velocity as a purely physics controller, hence, away from input stuff.
I have tried both transform.translate and Vector3.Lerp. I cannot seem to increase the speed of the move without either making him teleport directly to the destination or the destination changing. Here is what I am currently using:
Getting the input:
if (Input.GetAxis("Horizontal") > 0 && !doingheavy)
{
gravity = 0;
if (linkwindow)
StartCoroutine ( quickright () );
else
StartCoroutine ( heavyright () );
}
The Kick animation
IEnumerator heavyright()
{
oldpos = transform.position;
animating = true;
doingheavy = true;
StartCoroutine( kickright () );
yield return new WaitForSeconds(1f);
gravity = -0.7f;
rightkick = false;
animating = false;
}
Finally, here is the part I am having trouble with:
if (animating && rightkick)
{
transform.position = Vector3.Lerp(oldpos,
new Vector3(oldpos.x + 4, oldpos.y + 1, oldpos.z), Time.deltaTime * 4);
}
The only problem with the above one is that teleports him to the destination point. I have tried changing the time.deltatime multiplier to all different types of values but there doesn’t seem to be something that smooths out the movement the way transform.translate does. I have also tried using transform.Translate:
if (animating && leftkick)
{
transform.Translate(new Vector3(-200, 0, 0) * Time.deltaTime, Space.World);
}
And another variation of translate:
if (animating && leftkick)
{
transform.Translate(40 * new Vector3(-1, 0, 0) * Time.deltaTime, Space.World);
}
As I have said, when the multiplier or the Vector3 x value are manipulated in translate, it changes both the speed and distance traveled. I just want to make a move that looks very fast, but does not travel a huge distance. Lerp gets the destination point right, but it fails at producing smooth movement. Translate fails at stopping at the right destination point but it is smooth.
Am I on the right track? Perhaps I should add a condition that makes him stop? Any tips would be appreciated!