Hi, i’m having some problems with lerping locations and rotations.
I’m making a Platform game in which i manage Camera Movement though Target points by triggers.
I use lerp with a timeline to smooth the camera location and rotation while changing points but it doesn’t work properly.
I set the timeline’s float value to go from 0 to 1 in 5 seconds, just to test it, but after starting (with Play on Start) the camera finishes to move/rotate in less than 1 second instead doing it all in 5 seconds, however the float return value works fine, 0 to 1 in 5 seconds. What’s be the problem?
I take the world location and rotation of the camera and from the new target point.
Hope for a prompt response. Thanks.
You can’t use lerps with ‘get’ nodes. With a lerp, you have to pre-calculate the current location and target location ( rotation etc ) and then just plug those variables into the lerp.
You’re getting the world location and rotation during the timeline. You have to put the current location and rotation in variables, same with the targets you’re going for. Then run the timeline with the lerp just taking in those variables.
i wouldn’t say current location in this case, its more of a start and end location that need to be static. current makes it sound like the variable needs to be updated.
the issue with using non static vectors for the lerp is that the locations are updated each time the timeline updates which will cause a inconsistency resulting in a exponential acceleration of sorts. for example if you were to use your current setup: at time 0.5 the output vector should be halfway between point a and b, but since your updating the start location the lerp will constantly be trying to use the location between the actors current location and the end point, so if at time 0.5 your actor is already half way to the end then the lerp will try to output a location 3/4 the way to the end. hmmm its hard to explain.
maybe it would be better to explain another way. lets use a static alpha of 0.5 and locations 0 and 10. if you have static locations for A & B then your actor would stay in one spot (location 5) between A & B right. but in your case due to the get node you would be getting a location that changes each time like this: for the first time its run the output location is 5 as it should, but then we set location A to the actor location which is 5, then we run the update again (get point 0.5 between a & b) now its 7.5 and we set the actor to that location, the third time we set A again it will return 8.75, etc. your basically removing 50% of the distance to the goal each update instead of remaining stationary. in the actual script you have your removing alpha percent per update. so if you updated 4 times total it would remove 25%, 50%, 75%, 100% resulting in locations (2.5, 6.25, 9.06, 10) instead of (2.5, 5, 7.5, 10).
Bottom line is when using a timeline with a lerp use static values for the A & B pins. So get your initial values, save them to variables, then use the variables as the A & B values. And don’t change the variables while the timeline is running.
for your script you will want to go to your get world location node at top left and right click the output pin, select promote to variable, then insert the set variable node just after the move to point event (where your first print strings are). then you can either get that variable or drag off the out pin on the set node and connect that to the A pin on the lerp vector. That’s assuming that scene component that your getting the location from is moving.
I’m not sure on your end location but you could do the same as the above and make it a variable as well if its going to move about.
Repeat for the rotations as well. Or you can combine the location and rotations into a single transform variable and break it as needed.
Ok thanks for the help everyone. i tried to do like you suggested, i just added two more parameters to Move to Point, now it has:
Start Location, Start Rotation, End Location, End Rotation (i think it’s better use transforms at this point) and now the interp works! doing another test, i found that i can also use those Get nodes but instead using Alpha value from the timeline i could use Get World Delta Seconds and the result is almost the same, maybe smoother.
Just another issue that i don’t get how to solve:
Every time i play the game, and then i stop it, UE warns me a couple of same errors:
Blueprint Runtime Error: “Accessed None trying to read property ActualCamera”.
ActualCamera is a reference of my Camera inside the level, i take it from my GameMode on its BeginPlay with GetAllActorsOfClass and save the first (and the only one) value in a variable.
It seems like in a certain point of the Runtime the program does not found the level camera. Tell me what i had to screen. Thanks.
When you get the error, click on the last link on the far right, it will take you to the node that is actually referencing the null pointer. Work you way back from there…
The problem is that all works when playing, without crashs. The errors rise up only when i stop playing.
the nodes that the log shows me are on my PlayerController’s tick and in an actor’s BeginOverlap that should set some data to the camera, but these two nodes get a none camera. is there an alternative way to save a reference to the level camera before everything starts to tick or even be called?
Ok i resolved it. One last thing, i hope XD
What about this? when i stop the game UE warns to me two other, and similar, errors.
the first time this node is called i choose to not put a CameraPoint into the struct.
if there’s a point i use some of its data to the camera, else i get data from the struct. Only SetNewRotation has a None problem, even if i told it to not take from the point if None. What could it be?