I’m looking to create an effect of objects moving based on player location starting from one point and ending at another. An example of this could be a brick hallway that begins to close behind the player gradually as they walk through it, but gradually return to the original state when the player walks back to the entrance. I’m not exactly sure where to begin with doing this effect.
@Sorai A very similar effect ( and maybe what you’re thinking of ) is achieved by having a box trigger in the door region. When the player overlaps, it triggers the ‘play’ on a timeline, when they stop overlapping it triggers the ‘reverse’. If you step in and out of the box while the door is trying to move, it will keep bouncing between closing and opening, depending upon your position.
If you actually want to control the door position depending upon the player position, then it’s a little bit more fiddly. You still need a trigger volume, and you can measure the distance between the player and the door frame and control the door accordingly. But this would probably look a bit weird…
You can actually get a direct measure of the player’s position down the hallway. Get the player’s world location and use “inverse transform” by the hallways world transform. Then break out the vectors X (or vector Y if you hallway’s sideways) will yield the players relative progress made down the hallway. Break vectors by right-clicking the yellow plug and selecting “split” or you can drag out the yellow wire and type “break”. You can also just drop a empty actor into the scene and use its transform instead of the hallways, just means you don’t have to push around vectors as much.
You can run off tick to update the walls positions (or hallways scale) every frame based on X. Then fill the whole hallways with a trigger box so you can pause tick when you leave. Tick can either be paused with a simple branch (and bool), you can use node “tick enabled” and leave it unchecked. If you want to avoid using tick, you can right-click and type “add timeline”, double click the timeline and check looping, then add custom events to the timelines play and stop, use the timelines output as a tick.
If the hallway is curved in any fashion, you might want to try using splines and somehow get the players distance along the spline, then the distance would drive the walls transforms. There’s a mathy way to get distance along spline based on world location that involves using the “nearest” set of nodes related to splines. I’ve solved it already and will post it up once I get to my laptop. In any case, the bendy hallway won’t look good with just moving locations or scaling around, you’ll want to actually push the face normals in the material instead, but then collisions will be a bit tougher.
How to find your relative position to the hallway (or any object), just using x gets you your progress through the hallway:
This is also useful for finding if object are left or right of the player (they would be Y+ for right side).
and this is how to find your distance along a spline:
I use this any time I have to drive an object along a spline path, specifically if the object was first free-roaming or has to transition from another spline but it should prove useful for you here. You’ll use this to calculate your distance along the spline, once you have that distance you can divide your current distance by the length of the spline to get percentage.
Thank you both. I’ll be experimenting with this over the next few days.