Making Force Grip/Grab
I have a question about moving objects in unity I want for lack of a better word "force grab" in my game to pick something up with a button press and move the object with it in the centre of the camera while moving the object with the camera (my game is first person) like star wars force unleashed if that helps. my problem is i want to set the distance from me to the object so it is not clipping in my face and i also can not make it move forward or backward as the player movesi know this is because the mouse postion did change so is ther another way to make this effect i am missing.
here is what i got so far
private void ShootGrab() { RaycastHit hit; if(Physics.Raycast(myCamera.transform.position, myCamera.transform.forward, out hit, range)) {
Rigidbody target = hit.transform.GetComponent<Rigidbody>();
target.useGravity = false;
target.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z));
print("hit");
}
}