Answer the question
In order to leave comments, you need to log in
Coordinate transformation (function graph transformation) for character movement in unity?
Hello everyone, here is the key code D , which implements the movement of the character to the side with grief-in-half (more precisely, it turned out diagonally, but not the point)
if (Input.GetKey(KeyCode.D))
{
PosZ = PosZ + speed+PosZ* Time.deltaTime;
Newpos = PosZ;
Vector3 directionD = new Vector3(Newpos*-1, hero.transform.position.y*-gravity, hero.transform.position.z);
hero.Move(directionD*Time.deltaTime);
lastPressedDTimeD = Time.time;
if (Time.time - lastPressedDTimeA < threshold)
{
PosZ = PosZ + PosZ * -1;
}
}
if (Input.GetKey(KeyCode.A))
{
PosZ = PosZ + speed+PosZ * Time.deltaTime;//к текущей позиции добавили в направлении вперед немного))
Newpos = PosZ;
Vector3 directionA = new Vector3(Mathf.Sqrt(Newpos), hero.transform.position.y * -gravity,hero.transform.position.z);/*= new Vector3((Newpos * -1) * Mathf.Sqrt(Newpos * -1)*/
lastPressedDTimeA = Time.time;
hero.Move(directionA * Time.deltaTime);
if (Time.time - lastPressedDTimeD < threshold)
{
PosX = PosX + PosX * -1;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question