I have a character in game that when I press the left mouse button, it spawns a ‘ghost’ of something. Now I want that ghost’s location to be limited to a certain distance from my character (this will stop that ghost from going everywhere around my map).
Is there a good way on doing this?
From what I heard, ‘Vector Length’ would be the best way to go, but even then, I’m not sure on how to approach this.
Assuming everything else is set up, and all that is needed is the ghost location limits, how will I go about doing this?
From how my logic works (which it doesn’t), i would assume:
I need to obtain the character world location
Then get the ‘ghost’ actors location (‘Get Actor Location’)
I would then have to find a point in between these two (close to the character)
Then if the ‘Ghost’ is out of these limits, than set its location to that limit (some how)
Hopefully this makes sense to you all, if not, please tell me what I need to elaborate this issue.
Maybe you could create an invisible sphere component around the character with a custom collision on it that only affects the ghost, “physically” preventing it from passing through it’s radius.
Get world locations of both actors.
Get vector from object to the player (ie world location of object minus location of player) name this as “offset vector”
Normalize that vector (offset) name result as “direction vector”
Get length of “offset vector”, clamp it inside your limits (min to max distance from object to its ghost.)
Normalize vector, this will give you vector with length of 1 that points into correct direction.
Then multiply it by how far you want ghostt from player.
and then add that vector to player location.
Edit.
Yes like this exactly. Result vector is what you want add or substract to player world location.
Or to mesh location. All depends where you want to have that ghost.
Ps.
To make ghost bit better you can scale it up or down. 1.1 if you make ghosts near source mesh. .9 or less if you want ghost near player.
So with that, how would i go about making the limits to this? For example; I wish to have the ghost to have a limit of ‘.1’ towards the character.
So i would have to say…
IF the ‘ghost’ is greater than the mesh location (+ .1 or something?), than set the ‘ghosts’ NEW location to the limits?
Also, will this work even if I move the mouse around the outside of the limits (as in, will the ghost try and follow my mouse around, but not going outside those limits)?
Well I understand you want to use vector length, but the whole point with custom collision settings is that it only affects what you want it to affect.
Also, i think this also effect the orientation of my camera. I believe this is normalising from my character (centre of the screen), to the edges of the window (0 = character location, and 1 = window boundaries).
I wrote you formula how to calculate new ghost location. My both posts were about finding location for ghost mesh. That was answer to problem you wrote about.