Move to Teleport location instead of Teleporting?

Hello you! :cool:
I am currently in need of a little advice and pointers. I am currently using the UE 4.13.1 VR Template and as the title says I’m hoping that it’s possible to have the “Player/Camera” move at a set speed to/towards the teleport location instead of magically appearing there. Is this possible to do without coding experience? Because I have none, sadly.
I’m guessing it has something to do with the MotionControllerPawn but I am clueless as where to even begin poking around.
Gotta learn stuff the hard way, trial and error, but with your help it will hopefully be with less errors! Hehe!

Anyway, I hope I was clear about what I would like to be able to do, and here’s to hoping that is has a simple solution!
Thanks in advance and thanks for reading!

Short answer: Yes. You can do it in blueprints.

I get the feeling that it’s not the lack of coding experience that’s going to cause you trouble, but the math behind it. The camera has a position and orientation and your destination has a position as well, so moving from the start position to the end position over a period of time at a fixed speed is a pretty straight forward math problem.

I made this in a pawn BP. I don´t use the template. But maybe it helps. Attached is a screenshot.
Basically you take the actor location, capsule component (temp loc) in my case and the impact point location (temp loctarget) from a single line trace and blend those with a timeline through a SetActorLocation. The temploctargets z coordinate gets added the size of the capsule half height, 100 in my case so you don´t get stuck in the ground once teleported. The characters rotation at the destination is automatically the rotation of the initial point of teleporting. When teleporting you will just fly through objects that may be in your way. To avoid getting stuck in walls I allow the tracing only to some specified ground objects. This is very flexible as the timeline curve lets you precisely control how long the motion lasts and how smooth it is. But I warn you this way of motion causes heavy motion sickness :slight_smile:

I think straight movement with a const speed isn’t very bad. Just don’t use corners smoothing in timeline :slight_smile:

Cheers! I’ll look into stuff that has to do with camera positions and orientation!
And you are correct! I have a lot of trouble with math, I only know the very basics but if it involves coordinates and positions and what not then I’d have better luck swimming in shark infested waters with a open flesh-wound >.<
Hopefully I’ll be able to manage!

Thanks for taking the time to reply!

Thank you so much for setting up an example and explaining how it works! I’ll definitely look into and try to make my own “blank” project using your help to try and understand how it works.
As for motion sickness, I haven’t had much problems with different types of motions, “Onward” the game caused some when moving up stairs but other than that I’ve been fine. The intention was to move fairly slowly but if I get motion sick from it then I just might have to scrap my idea all together hehe.

Thanks again for providing an example!

The problem is the way I set it up. The time to fly to a location is always constant, so the speed varies depending on the distance. I don´t think it´s possible with a timeline to keep the speed constant while the time varies. But I might be wrong. So when teleporting to a far distance you will accelerate and move very fast. We tested this here in a room scale setup and some people nearly fell over :slight_smile: A solution might be to limit the trace distance so that you can´t move over far distances. I decided to offer both ways. I set up both a simple teleport and a smooth moving. I can switch between both modes by pressing a button. Attached is a screenshot. So there is mode for any kind of stomach^^

Here is another way with a constant speed.

MovementSpeed - required speed (cm/sec)

on teleporting start:
SetActorTickEnabled(true)
Alpha = 0.f
StartPoint = GetActorLocation()
AlphaMultiplier = MovementSpeed / VectorLenght(EndPoint - StartPoint)

On Tick():
Alpha += DeltaTime * AlphaMultiplier
if (Alpha >= 1.f) { Alpha = 1.f; SetActorTickEnabled(false); }
SetActorLocation (Lerp(StartPoint, EndPoint, Alpha))

If your use Tick function for another purposes just add some bool flag insted of SetActorTickEnabled(…) calls.

You should definitely brush up on your math skills then :slight_smile: It is by far the most valuable and frequently used skill set I have when it comes to game dev and VR. When you’re learning math, you’re learning how to be a better programmer and game developer :slight_smile:

So, let’s talk about this super simple math problem you’re approaching…

You’ve got a start position, a current player position, and a destination position. These will all be vector3’s, which each have an X,Y,Z component. We’re going to assume that the camera is attached to the player.

When the player gives a movement request to go from point A to point B, you want to move them there at a constant speed. Since we’re moving characters on a per-frame basis, we’re going to be applying a fixed velocity to the character each frame.

So, let’s pretend that you start off at point A [0,0,0] and you want to move to point B [10,0,0] and you want to arrive there in 2 seconds. In other words, you want to move +10 units on the X axis in 2 seconds. So, your velocity vector is going to be 10 / 2 = 5 units / second. Speed is the distance traveled over time, just think speed limit signs and car speeds: they travel in miles per hour, which is distance units over time. A vector contains speed AND direction, so if we want to move with a velocity of 5 units / second on the positive X axis, we our velocity vector will be [5,0,0].

Okay, so we’re moving by a given amount per frame, and there are LOTS of frames per second. The frame rate is variable, so it can be anywhere from 1 frame per second to 90+ frames per second. Thankfully, we know how much time has elapsed since the last frame because the engine gives it to us in a “delta time” variable. The delta time is the time stamp difference between the current frame and the last frame, so it’s always accurate. Let’s say we’re running at a fixed 60 frames per second. If we want to move our character by 5 units per second, how many units do we move per frame with 60 FPS? That’s easy: 1/60 * 5 = 0.0833

Anyways, we can condense all of this stuff down into a couple lines of pseudo code:



void YourCharacter::Tick(float deltaTime)
{
     Position += Velocity * deltaTime;
}

FVector YourCharacter::FindVelocity(FVector StartPoint, FVector EndPoint, float TimeSpan)
{
     //distance & direction / time units (think: miles per hour)
     return (EndPoint - StartPoint) / TimeSpan;
}