The player in my game can levitate objects and move them around on the world xy with the mouse. How can I make the levitating object move with the player when he moves?
private void levitateObject() {
//Debug.Log("Levitating");
float yAxis = Input.GetAxis("Mouse Y");
float xAxis = Input.GetAxis("Mouse X");
Vector3 frontForce = playerCamera.transform.TransformDirection(Vector3.forward) * (yAxis * 1.5f) ;
Vector3 rightForce = playerCamera.transform.TransformDirection(Vector3.right) * (xAxis * 1.5f);
Vector3 currPos = levitatingObject.transform.position;
Vector3 nextPos = new Vector3 ( levitatingObject.transform.position, elevation, levitatingObject.transform.position) + rightForce + frontForce;
levitatingObject.GetComponent < Rigidbody > ().velocity = (nextPos - currPos) * 10;
}
I want do something like the below but then my object doesn’t move at at all
Vector3 nextPos = new Vector3 ( transform.position.x + (levitatingObject.transform.position.x -transform.position.x) , elevation, transform.position.z + (levitatingObject.transform.position.z -transform.position.z));