Unusual movement script. Any ideas how to do that?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public float speed = 3f;
private bool moving = false;
public float zPos, xPos;
public bool move = false;
public SwipeManager swipe;
private bool IsMoving = false;
private Animator animator;
// Start is called before the first frame update
void Start()
{
xPos = ChangeXPos(1);
zPos = ChangeZPos(1);
animator = transform.GetChild(0).GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
int swipeDir = swipe.GetSwipeDirection();
Debug.Log(swipe.GetSwipeDirection());
switch (swipeDir)
{
case 1:
animator.SetInteger("direction", 1);
break;
case 2:
animator.SetInteger("direction", 2);
break;
case 3:
animator.SetInteger("direction", 3);
break;
case 4:
animator.SetInteger("direction", 4);
break;
case 0:
animator.SetInteger("direction", 0);
break;
}
}
bool Step (Vector3 targetPosition)
{
bool success = false;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
if(transform.position == targetPosition)
{
success = true;
}
return success;
}
bool ZStep(float zPos)
{
bool complete = false;
moving = true;
if(Step(new Vector3(transform.position.x, transform.position.y, zPos)))
{
moving = false;
complete = true;
}
return complete;
}
bool XStep(float xPos)
{
bool complete = false;
moving = true;
if (Step(new Vector3(xPos, transform.position.y, transform.position.z)))
{
complete = true;
moving = false;
}
return complete;
}
float ChangeZPos(int dir)
{
if(dir == 1)
{
return transform.position.z + 5f;
} else
{
return transform.position.z - 5f;
}
}
float ChangeXPos(int dir)
{
if(dir == 1)
{
return transform.position.x + 5f;
} else
{
return transform.position.x - 5f;
}
}
IEnumerator wait(float wait)
{
yield return new WaitForSeconds(wait);
}
}
Can someone please help me to make a script that dmoves the player for +5 or -5 by each coordinate when player inputs a swipe(1 - up, 2 - down, 3 - left, 4 - right, accesed by GetSwipeDirection() in Update()), so when player input for example 1 player must move to transform.position.z + 5f smoothly using moveTowards. And yep that's not even all. How to check when the player is moving up for example that if on the right or left there is nothing then stop. I am really stuck with that.
Comment
Your answer
Follow this Question
Related Questions
Jumping in my script deosnt work,How make this script to jump? 0 Answers
Character Rotation 0 Answers
Continous movement issue 0 Answers
Movement acceleration 1 Answer
How can I state the movement speed of this script? 0 Answers