Advertisement
Guest User

Untitled

a guest
Apr 14th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class PlayerController : MonoBehaviour
  7. {
  8.     public float moveSpeed = 5f;
  9.  
  10.     Vector3 startingPos;
  11.     Vector3 currentPos;
  12.     Vector3 targetPos;
  13.  
  14.     private void Start()
  15.     {
  16.         startingPos = new Vector3(0, 1.1f, 0);
  17.         currentPos = startingPos;
  18.         targetPos = startingPos;
  19.     }
  20.     private void FixedUpdate()
  21.     {
  22.         if (targetPos != currentPos)
  23.         {
  24.             Debug.Log($"Moving from {currentPos} to {targetPos}");
  25.             transform.position = Vector3.MoveTowards(currentPos, targetPos, moveSpeed * Time.fixedDeltaTime);
  26.             currentPos = transform.position;
  27.         }
  28.     }
  29.     public void SetNewDest(Vector3 target)
  30.     {
  31.         targetPos = target;
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement