I want to make something like this https://www.youtube.com/watch?v=_BPb68CvnEk which is basically when camera looks into something I can posses it or control it, like controlling the camera or opening the door, turning on/off the lights.
I have a concept of how that would work, but I can’t figure out how to make it into code or blueprint.
Can someone help me out?
It sounds like you just want to be able to look at something and hit a key to interact with it in a specific way, correct? **Possess **means something very specific in Unreal and I don’t think that’s quite what you need (unless we are talking about possessing/controlling actual pawns). The key difference here is that if your **controller possesses **another pawn, you lose control of your previous pawn.
All you should need to do is make an interface for interacting. Put that interface on anything you want to be able to interact with. Give the character an invisible primitive component that can overlap - maybe like a big capsule. Add a function to the interface that fetches a sphere component on the item that will be used to detect the item as being in range for interaction. The character’s capsule and the items’ spheres should use a new trace channel only used for detecting overlaps between an ‘interactor’ and an ‘interactable’. On the character, when an overlap with an interactable is detected, add it to a list of overlapping interactables. When it ends overlap, remove that item. On tick on the character, go through the list of overlapping interactables and pick the best one. You can do this by scoring them based on how close they are to where you are aiming and how far away they are. The general idea is that if they are close to your aim and close to your character, it should be higher priority. Once you know what the best interactable is, you can do whatever you need to with that info - like display a widget using its location.
You should have an interact key (technically you could do the following with any number of keys you wanted). If you press the interact key, we take a look at your most recently cached best interactable. If none, do nothing. If you have one, call an ‘Interact’ function on your interactable interface that can do whatever that object wants it to depending on how its overridden.
That’s the high view - I’ve done this in my own games before and it turned out really nice and easy to expand. Hope it works out for you.
This is what I came up with, but I got stuck with overlaying those channels, My brain literally stopped working How can I now make actor/pawn traceable by my character?
Thanks for the help though. In advance
And what about the case when you activate a part of an actor - you get behind the wheel of a ship (but you don’t directly control the ship, but only the steering wheel, which already affects the movement)? For such cases, is Possess well suited or something else?
Btw, if you are sphere tracing with a radius of 0, you might as well just line trace.
What do you mean by “make actor/pawn traceable by my character?” You have an actor and you want to be able to trace for it? It doesnt matter who is doing the tracing btw. This all depends on how your trace channels are set up on the collision of the thing you want to trace for. Right now you are tracing with trace channel ‘Camera’ which probably isn’t what you want. You’ll have to compare which channel you trace with and what the things you want to trace for have on their collision settings.
For that case, you would probably want to treat that as ‘interacting’ with the wheel of the ship. You would have a ‘begin interact’ key as mentioned, and for cases like this maybe a ‘stop interaction’ key. When the wheel is successfully interacted with, you start suppressing the player’s normal inputs (as in, you block wasd, ect feeding into how they are moving) and you attach the character to the ship at the desired location. This is great for a first pass, but eventually you’d probably want to get some dynamic animation going so that when the interact starts, the controls are suppressed and the character uses animation to finish walking to the preferred place you want them when interacting with the wheel. Once they are interacting with the wheel, you start piping their inputs into making the ship steer. If the stop interaction key is pressed, you detach them from the ship so they can move separately from it and unsuppress their normal controls. At no point during this whole process do I recommend possessing or unpossessing - its not needed and just adds more complications.
Thank you guys for the replies, I really appreciate it!