Pivot Based Follow Behaviors

Pivot Based Follow Behaviors

Hey everybody. Today we’re going to be walking through how to set up a group of elements that follow a particular center point in a few different ways.

I’ll show you the demonstration here.

So, these objects can appear, and they can orbit that location from several different points or they can be positioned relative to them somewhere in the world.

So, for example, if you wanted there to be a bunch of planets and they’re all around the sun and they’re out in the, in the solar system but then you want it to go to the user’s hand and then they come over and they spin around and then they can eventually go back out to the to the solar system.

It’s kind of like an orbiting or attractive object system and it requires a few different components to work.

So, if we were to take that center pivot which all the items will rotate around, that pivot can be in a few different locations.

In the Solar system example, it could either be where the sun is.

Let’s pretend I’ve finished all that, or it could be where the, where the VR player’s hand is.

So, you know, they’ve, they’ve got their handout.

Let’s pretend that looks even vaguely like a hand, some buttons on the top.

And perfect.

Okay, so the VR player needs to have a pivot point on his hand and the Sun also needs a pivot point, in its center.

The Sun would then have instructions for where Earth and Mars and Mercury and Pluto out here would go.

And then around the player’s hand, there’s an ordered set of imaginary positions around it that would bring them all over and attracted around the hand versus being out in the solar system.

So how do we do that?

We do it by having an environmental setup.

So, I’ll escape here.

You have an environmental setup where we define locators for where we want these items to be.

So, in this case, you’ll see these red arrows are those locators.

And I just gave it an arbitrary name.

Like, I think I gave it an actor tag of the environment so that it knows, oh, I’m gonna, or attraction underscores environment.

So, notice to go out, find this attraction underscore environment object and that’s where its pivot point needs to be, right here.

And then it knows to look through the attraction environment, find all of its child elements, all these arrows and use those to distribute whatever tracking elements that currently has the planets.

Then there’s a hand, an imaginary hand which right now is just an empty point in space in front of this display where when it attracts toward the hand, instead of needing to have specific points to position elements, it actually just calculates an orbit around it and distributes the elements in a circle.

The way that it distributes elements is like this.

So, if we have, if we have our locator and then we have a circle which is 360 degrees, we know how many elements we have, eight or nine if you consider Pluto.

And depending on that, you would do division to know how many degrees per object you need.

And based on that, you would first place the one here and then go by that degree value and do it again.

And again, and again until you reach back over here.

So that is along one plane, you’ve drawn a circle.

Then to make it feel more natural you want there to be not only a forward and left right variation.

If this is the hand from the side where you have these elements you also want there to be an up and down variation to make it feel like they’re random, even though it’s getting distributed you want it to have some fun randomness.

And the way you do that is with a mathematical equation.

So, so you could use a sign wave so that you know, they’re distributed like this around, you would have one planet here and one planet here and one planet here around, around the hand or you could do Perlin noise.

Perlin noise is a commonly used natural-seeming randomness that doesn’t necessarily follow an easy to perceive a pattern.

I’ve just made this up.

That goes between a negative one and one.

And it’s not so constant like, like a sine wave.

So, it’s not repetitious to the eye.

So, I used Perlin noise.

And oftentimes you combine a sine wave with two Perlins and do that type of thing, but that’s more for terrain generation.

When you want terrain to look natural, you combine a bunch of different things.

I’m just doing one Perlin.

And so, if we look at that in code, we have two objects.

We have the spheres themselves that need to be told some vertical offset.

They need to be because they’re moving around from a pivot by the attraction controller kind of the center of that solar system, is moving the whole thing around.

And then each element is told how much vertically to be offset that way they can move, and it doesn’t matter how high or low they are I don’t have to center by this thing.

I center by, by some imaginary pivot that is at a constant Y height or in unreal terms is the Z height but they’re all at the same height.

And then getting told to move different levels from there, the planets themselves.

So, the attraction controller then takes its satellite components after it’s created them.

So, on start, we create all of our components.

It doesn’t matter how we’ve created them; we could spawn them in place, or they could already exist in the world.

If we, if we find them all and then we tell them all to do something in this case I tell them all to just default to being around the hand, not around the solar system the Sun or whatever it is in the distance, the environment.

And then every frame we have to do decide whether or not we should do particular things and move it toward particular locations.

And the artists have the control to tell them when to reveal, when to go to the hand, how far from the hand they should be when they should return to the environment and when they should fade away.

So that’s the important part because having all these features is only as good as being able to tell the artists how to do it.

So now that we have special hooks that make all these controls work you can just have them all be functional in an order.

So, for example, in this attraction controlled or demo, when you step up a button just like what an artist would do, they would do everything in order that said, okay, I’m going to spawn, and then I’m going to pull and then I’m going to wait a few seconds.

And then if I haven’t already been if you haven’t already stepped off the button, we’re going to have it go back to the environment or push away or, and then despond in the end.

So, with all that knowledge, now we know when I step on this button It’s told to go to the hand using that orbit math with the degrees and the Perlin noise.

So, you’ll notice they’re all at slightly different heights, they’re not in line.

And then they’re told to get farther and farther away.

And then they’re told to go into the environment.

And then they’re told to fade away, as you can see.

So, boom, I’ll have them come in, I’ll have them fade away, fade in, fade out, that easy.

And that’s how we did a little orbit controller.

Thanks for watching.