using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
struct MyVector
{
public float x, y, z;
public float magnitude
{
get { return Mathf.Sqrt(x*x + y*y + z*z); }
}
public MyVector normalized
{
get { return new MyVector(x / magnitude, y / magnitude, z / magnitude); }
}
public MyVector(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
public static MyVector operator +(MyVector a, MyVector b)
{
return new MyVector(a.x + b.x, a.y + b.y, a.z + b.z);
}
public static MyVector operator -(MyVector a, MyVector b)
{
return new MyVector(a.x - b.x, a.y - b.y, a.z - b.z);
}
public static MyVector operator *(MyVector a, float d)
{
return new MyVector(a.x * d, a.y * d, a.z * d);
}
}
public class PlayerController : MonoBehaviour
{
[SerializeField] private float _speed = 10f;
private void Start()
{
MyVector a = new MyVector(10f, 0f, 0f);
MyVector b = new MyVector(5f, 0f, 0f);
MyVector dir = a - b;
dir = dir.normalized;
MyVector newPos = b + dir * _speed;
}
private void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * (_speed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.back * (_speed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * (_speed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * (_speed * Time.deltaTime));
}
}
}