Question by
fardinhojat8 · Nov 21, 2020 at 12:00 AM ·
vector3
How to keep a fixed distance between two game objects while keeping it inline between the cursor and the other game object?
I have a player, cursor, and firepoint game object. I want the firepoint to be a fixed distance away from the player but still inline with both the cursor and the player. I'd like to do it without the use of rotations and only using vector additions/subtractions. I so far can get the point to be on the cursor but I am not sure how to make it as I described.
public GameObject playerPrefab;
public Camera cam;
public GameObject firepointPrefab;
void Update()
{
firepointPrefab.transform.position = cam.ScreenToWorldPoint(
new Vector3(
Input.mousePosition.x,
Input.mousePosition.y,
-2)
);
}
Comment
Your answer
Follow this Question
Related Questions
Main Camera automatically increment by 0.75 on Y axis 0 Answers
how to calculate the angle between two vectors? 6 Answers
Make camera tracking the view in VR 1 Answer
Trying to Generate Different Random Values for Position of Game Object Instances [C#] 1 Answer
How do I find the rotation of a game object in relation to its grandparent 1 Answer