So I have another question out there, but figured I’d broaden my question.
I’ve searched all through the forums, answerhub, and other sites looking for information, but either I’m missing it or it’s not there.
I’ve come now to question what the best way is to move the camera in 3rd person? What I’m wanting, is on certain actions, for the camera arm to zoom in a little, and zoom back out when the action is complete, on things like sprinting. So there would be a set float destination, and the camera would ease into that position, and then ease back out to the original location. I already know how to change the camera arm position, but it just jumps over. I need it to ease smoothly into each position.
I’ve read on using InterpTo, but have no idea how to get it to work right. I’ve looked at using a timeout, but that seems like it should be a last resort in my own experiences (don’t use them if you don’t have to, especially if anything will be online). What is the best way to do this? Could someone please explain, and possible provide an example?
I use the IsNearlyEqual because I am dealing with floats with some possible inaccuracy between them. CameraBoon is my spring arm the camera is attached to. Every time I “zoom in” or “zoom out” I add that value to my variabl desiredBoonLength. Then each tick I check to see if desiredBoonLength and TargetArmLength are not equal. If they are not, then I interp each tick until they are close enough.
I’ll try this when I get home this evening. One issue I’ve had with interp is knowing exactly how to pull deltaTime as well. I think I’m doing it right, as I can get it to print out on screen, but am just guessing still. Can’t show the code as I’m at work right now. Also, could you give an example of using a tick? I’m quite new with unreal, and still learning how exactly to do things in the engine, on top of it being a couple years since I’ve heavily messed with c++.
Is there a way to do this purely in c++? Out of preference, I’m trying to stay away from blueprints at all. I looked a little at moving the FOV, and am going to continue to now, but didn’t see much on transitioning it smoothly between two values.
Okay I’ll give you the UE4 run down real quick. Pretty much everything except for components inherit from from Actor. Anything that can be placed in the world is an derived from Actor. Things that are placed on actors are components and inherit from UObject. So you have two base classes to chose from, UObject and Actor. Now Actors also inherit from UObject but as stated above Actors are specifically any object that can be placed in your world, this includes a Pickup to your character and static scenery and everything visually represented in the game world.
Now I went over that for a reason. Every actor has a Tick function that you can override:
Tick is automatically called by the engine for any actor within the game world. Notice I did not pass deltaTime into my CheckCamera function. I could have but I wanted to demonstrate the other way to get deltaTime as well.
The above is part pseudo code part directly taken from my own project but should illustrate how to get into the tick function and pass round deltaTime as well as how to get DeltaTime from any function called with out having to pass it in via function parameters.
One thing to remember is deltaTime is in milliseconds so every 1000 milliseconds is equivilant to 1 second. Why I bring that up is that is how the Interp function operates on, The zoom speed you give it needs to be unreal units per second.
Cool and thanks for explaining! So from what it looks like for my situation I just need to check if sprinting and camera arm location in the tick, if conditions do camera move back or forward. I’ll try this out tonight and comment or set answered!
The last project I worked on was a smaller ORPG, and the rule there was small things (like this) are fine in a tick/timeout, but limit server ticks/timeouts and client sends to server in ticks/timeouts to none if possible. Because of the possibility of online elements in my game, is this the same rule, or does it matter less in this instance? How heavy is this on the client, and possible server checks too (still trying to figure if I need to communicate the camera to the server, but not near that stage yet at all. Because of being new to unreal I’m not sure how exploitable the camera attachment to an actor, or in this case player, is without server checks)?
I do not think you would need to send camera information up to the server, just pawn location/rotation and any relevant state information. I haven’t worked much with the online systems yet but generally I believe Visual aspects such as camera placement is okay for the client while you only want to send “data” to the server for processing. I kinda think of server processing as a series of proposed questions “What will happen if I move there?”, “What will happen if I press the trigger/button?”, “Does the fire I’m standing in hurt?” The server handles these kind of questions while the client handles “I want to move there”, “I press the button”, “I am standing here and there happens to be fire”. The server then decides the outcome of those questions: “you move there”, “The door opens”, “You take fire damage”
Basically no one else can see what you see in the game, unless you want to make a spectator pawn that follows what the player sees, but even then that can just be “faked”.
Got ya. I feel dumb bringing that up but best to ask. The last game i worked on there was supposedly a hack to view others camera which caused an advantage in the game. I didnt have time to try yesterday but will do this for sure this evening.
no need to feel dumb, like I said I have not had any experience with the online systems of UE4 yet but the game I am working on does have a multi-player aspect which I will need to understand as well. Your question actually got me to better refine my own understanding of the online system. There truely are no dumb questions haha (especially on something as complicated as a game engine… unless your question is what is unreal engine 4 haha)
The sprint part of it does work, and the camera doesn’t move. I think I’m still missing something, but I just don’t know what.
Also, very, very sorry for such a late reply. Family issues arose and this had to take a break. Pops has been in ICU over 2 months now, almost 3, and still in.
Okay so you say you have override the tick function as we disused way back when, excellent.
Now… I see the definition you put there. And in the next steps you state you are doing this next bit of logic in the sprint started function. Question… is that function called continuously or only once? If so, that may be the issue.
You may need to add a flag such as
bool isSprinting
float originalLength
That is set to true on your Sprint Start and false on Sprint End function. Sprint Start also should Set the originalLength to the current length of the Arm. (though watch out for double sprinting, it will override the originalLength of the user presses sprint and then presses it again)
Then in your Tick function move all your logic for InterpTo from the Sprint Start to the Tick function :). If isSprinting is true, interp to the 700.0f length. If isSprinting is false InterpTo the originalLength.
The problem is C++ is not like blueprints, Tick is the only function that gets fired every… well tick. Most of your button events (except for Axis mappings) are called only once and so your InterpTo logic is only being executed once.