void Update() { if (Input.GetKeyDown(KeyCode.A)) { if (pathID > 0) { pathID--; currentPath = pathlist[pathID]; } } if (Input.GetKeyDown(KeyCode.D)) { if (pathID < 2) { pathID++; currentPath = pathlist[pathID]; } } float distance = Vector3.Distance(currentPath.path_objs[CurrentWayPointID].position, transform.position); transform.position = Vector3.MoveTowards(transform.position, currentPath.path_objs[CurrentWayPointID].position, Time.deltaTime * speed); if (distance <= reachDistance) { CurrentWayPointID++; //when current position is met, move on to next point } if (CurrentWayPointID >= currentPath.path_objs.Count) { CurrentWayPointID = 0; } }
void Start() { //path = GameObject.Find(pathName).GetComponent<PlayerPathFindingScript>(); lastPosition = transform.position; pathlist.Add(innerPath); pathlist.Add(midPath); pathlist.Add(outerPath); pathID = 1; currentPath = pathlist[pathID]; }
void Update() { if (Input.GetKeyDown(KeyCode.A)) { if (pathID > 0) { pathID--; currentPath = pathlist[pathID]; } } if (Input.GetKeyDown(KeyCode.D)) { if (pathID < 2) { pathID++; currentPath = pathlist[pathID]; } } if (Input.GetKeyDown(KeyCode.W)) { //transform.position = new Vector3(transform.position.x, 10, transform.position.z); jump = true; } if (jump) { transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, 10, transform.position.z), Time.deltaTime * (speed + 10)); if (transform.position.y >= 8) { jump = false; } } else { float distance = Vector3.Distance(currentPath.path_objs[CurrentWayPointID].position, transform.position); transform.position = Vector3.MoveTowards(transform.position, currentPath.path_objs[CurrentWayPointID].position, Time.deltaTime * speed); var rotation = Quaternion.LookRotation(currentPath.path_objs[CurrentWayPointID].position - transform.position); if (!rotation.Equals(Quaternion.Euler(0, 0, 0))) { transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed); } if (distance <= reachDistance) { CurrentWayPointID++; //when current position is met, move on to next point } if (CurrentWayPointID >= currentPath.path_objs.Count) { CurrentWayPointID = 0; } } }
void Start() { //path = GameObject.Find(pathName).GetComponent<PlayerPathFindingScript>(); jump = false; goDown = false; pathlist.Add(innerPath); pathlist.Add(midPath); pathlist.Add(outerPath); pathID = 1; currentPath = pathlist[pathID]; anim = GetComponent <Animator>(); head = GetComponent <SphereCollider>(); }
void Update() { if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") < 0) { if (pathID > 0) { pathID--; currentPath = pathlist[pathID]; } } if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") > 0) { if (pathID < 2) { pathID++; currentPath = pathlist[pathID]; } } if (Input.GetButtonDown("Vertical") && Input.GetAxisRaw("Vertical") > 0 && !jump && !goDown) { jump = true; movementID = CurrentWayPointID + 1; if (movementID >= currentPath.path_objs.Count) { movementID = 0; } } if (Input.GetButtonDown("Vertical") && Input.GetAxisRaw("Vertical") < 0 && !crouch) { crouch = true; head.enabled = false; } else if (Input.GetButtonDown("Vertical") && Input.GetAxisRaw("Vertical") < 0 && crouch) { crouch = false; head.enabled = true; } if (jump) { if (!goDown) { Vector3 vec = currentPath.path_objs[movementID].position; vec.Set(vec.x, 10, vec.z); //float newY = vec.x * vec.x + 2 * vec.x + 5; //attempt at parabola jump using quatratic equation //vec.Set(vec.x, newY, vec.z); //transform.position = Vector3.MoveTowards(transform.position, vec, Time.deltaTime * (speed + 10)); transform.position = Vector3.MoveTowards(transform.position, vec, Time.deltaTime * (speed + 15)); if (transform.position.y >= 8) { //transform.position.Set(transform.position.x, 1, transform.position.z); goDown = true; CurrentWayPointID++; if (CurrentWayPointID >= currentPath.path_objs.Count) { CurrentWayPointID = 0; } } } else { Vector3 downPos = new Vector3(transform.position.x, yPos, transform.position.z); transform.position = Vector3.MoveTowards(transform.position, downPos, Time.deltaTime * (speed + 15)); if (transform.position.y == yPos) { goDown = false; jump = false; } } } else { transform.position = Vector3.MoveTowards(transform.position, currentPath.path_objs[CurrentWayPointID].position, Time.deltaTime * speed); var rotation = Quaternion.LookRotation(currentPath.path_objs[CurrentWayPointID].position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed); if (CurrentWayPointID >= currentPath.path_objs.Count) { CurrentWayPointID = 0; } float distance = Vector3.Distance(currentPath.path_objs[CurrentWayPointID].position, transform.position); if (distance <= reachDistance) { CurrentWayPointID++; //when current position is met, move on to next point } if (CurrentWayPointID >= currentPath.path_objs.Count) { CurrentWayPointID = 0; } } anim.SetBool("jump", jump); anim.SetBool("crouch", crouch); }