Search code examples
unreal-development-kitunrealscript

Vector Rotator conversions in UDK


I've looked all around and find very little by way of actual code or function examples. Hopefully when (if) they get out of beta there will be some more effort put into documentation.

In UDK (2013-07 beta):

1) How do you convert a vector to a rotator?

2) How do you convert a rotator to a vector?

GetAxes()

3) Is there a function to set a camera to point at an object?

Anything that uses vectors typicaly has a LookAt() function, but seeing as these use Rotators I'm a bit lost.

4) Is there a function to set a camera to face along a vector?

This would be pretty easy if there is a vector to rotator conversion available.


Solution

  • For your first two question, they are simple:

    local Vector v;
    local Rotator r;
    
    r = Rotator(v); // 1: Vector to Rotator
    
    v = Vector(r); // 2: Rotator to Vector, v has now a length of 1 as a Rotator only describes a direction
    

    Further reading with examples concerning Rotators and Vector can be found here.

    A Rotator represents a direction without length. It consists of three angles in UnrealRot format to better utilize available memory. As Rotators only describe a direction, they will be converted to unit vectors (length = 1).

    Concerning your camera related questions, any kind of camera is possible but the implementation depends heavily on the context of what you want to do. The answer would be too long either way.

    Some tutorials I recommend:

    How the camera works in UDK, general concept with example code (official documentation)

    Vehicle camera tutorial

    Third person camera