I would like to ask how to define the trajectory of motion using unity 3D. I have object 1 and object 2. When the distance is less than a defined threshold, the object 1 has to move to the object 2 along the motion-trajectory from the sketch. How to define this motion trajectory using unity 3D? The motion is realized after pushing a key from the PC keyboard.
That trajectory appears to be a straight line. You can do this trivially by calling MoveTowards in an Update method. (In fact the sample script in the docs there is pretty much exactly what you want.)
You haven’t described what the problem is. Your code looks correct (assuming you want Cell to move towards target at 10 units/second while the P key is held down).
Is that a direct copy and paste? Because there are spaces missing in some very key locations and one bracket is missing.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NeedleMove : MonoBehaviour
{
public GameObject Point_Sphere;
public GameObject Cell;
public Transform target;
public float speed;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.P))
{
Cell.transform.position = Vector3.MoveTowards(Cell.transform.position, target.position, 10.00f * Time.deltaTime);
}
}
}