Vector Length Limitations

Hey guys, quick question;

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.

Thank you

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.

But this will effect more than just that specific ‘ghost’. Isn’t there a way to do it using ‘Vector Length’?

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.)

Multiply direction by clamped length.

Something like this?

AHHHHH like this?

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.

yeah but i would want to be able to expose these variables at a later time without exposing the collision values.

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).

Am i correct?

You are wrong.

Normalize - takes direction of vector, and makes its length exactly 1 and in same direction as input vector.

So steps I described above do this:

  1. remember direction from player to object.
  2. calculate distance from player to object
  3. clamp ie. calculate new distance you want put ghost object in
  4. place that ghost object either at some distance from player or from mesh.

Hey nawrot. Thanks for the help, but i think i have figured out what i needed…

However

Now i just have to figure out how to set the new location of the ‘Ghost’ actor to where it’s Last limited location was

And also update it to where my cursor is (without it going passed the boundaries).

Any ideas?

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.