N
N
Nekit Medvedev2019-03-25 10:37:29
Unity
Nekit Medvedev, 2019-03-25 10:37:29

How to force a child object to stop following the parent?

I'm trying to implement an aiming system like in the good old alien shooter.
For convenience, I made the sight a child of the player (since the angles in this case are relative to the player's position).
Naturally, a problem arose: when the player rotates, the sight also rotates, and therefore it starts spinning endlessly (
In my opinion, this problem can be solved in three ways:
1) Get the local coordinates of the sight, relative to the player, while the sight should not be a child.
2) fix the sight in global coordinates (extreme case)
3) analogue of the Vector3.Angle( , ) function with a given reference point.
I can’t show the code, since the script is only in theory.
I would like to know about the first and third

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2019-03-25
@NIKROTOS

4) make a hierarchy like {player}->{sight, model}, and rotate the MODEL. And the player only to move.
In general, why do you need to place the sight in the player's hierarchy? It seems to be unrelated things - the sight is on-screen, the player is the world one.

D
Denis Gaydak, 2019-03-25
@MrMureno

it does not spin correctly due to a couple of probable reasons.
- Wrong hierarchy
- Wrong code
- Something else wrong
I can't show you the exact answer, because it is also only in theory.
(as you saw that it is spinning, add the code and screenshots of the hierarchy to the question. for telepaths, this is for the battle of psychics)

S
stictt, 2019-03-25
@stictt

I would make the player model and the sight child of the controller on which the camera is attached, well, roughly speaking, a flying thing from the top. there will be no problems then with the hierarchy and everything else. It also frees you from a lot of problems in the future, and if you want to replace a player ? etc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question