Dear Community,

Here's the code to find a vector that is perpendicular to a given vector!

You also have the option of using a version of this code that will find a perpendicular vector relative to a given Actor's Rotation.

See the video for examples of both!

Make sure to call DrawPerps() in a tick() function, or have the drawdebugline bool set to TRUE for making the lines last permanently and only call it once.

but for the dynamic version you should definitely use tick()

but you probably don't need to DrawPerps(), that was just for the video

have fun with your perpendicular lines for whatever your project is

~~~

Here's the code I use in the video for thick 3d lines

I wrote it all from scratch

Example use:

~~~

With this code you can find perpendicular lines / vectors in 3D space, given either just a vector, or a vector and an actor's Rotation!

Enjoy!

Rama

Here's the code to find a vector that is perpendicular to a given vector!

You also have the option of using a version of this code that will find a perpendicular vector relative to a given Actor's Rotation.

See the video for examples of both!

Code:

//put this code in your player object class //does not need to be in HUD //since using drawdebugline //note debugline is slow //only used for testing purposes //I use my custom drawThickline //in the video //get perp line function vector getStaticPerpVectorTo(vector v1){ local vector v2; v2.x = v1.z; v2.y = v1.z; v2.z = -v1.x - v1.y; if(isZero(v2)){ v2.x = -v1.y - v1.z; v2.y = v1.x; v2.z = v1.x; } return v2; } //get perp line function vector getPerpVectorTo(vector v1){ local vector v2; local vector x, y, z; //based on rotation of this player object/Self //thanks for reminder about getaxes Spoof! getaxes(Rotation, x, y, z); v2 = v1crossX; if(isZero(v2)) v2 = v1crossY; if(isZero(v2)) v2 = v1crossZ; return v2; } function DrawPerps() { local int v; local rotator angle; local vector v1; local vector v2; local float len; len = 256; //draw along yaw angle.yaw = 0; for (v = 0; v < 50; v++ ) { v1 = Location; v1 += Vector(angle) * len; DrawDebugLine(Location, v1, 0, 0,255); v2 = getPerpVectorTo(v1 - Location); DrawDebugLine(v1, v1 + v2, 255, 0, 0); angle.yaw += 20 * degtounrrot; } //draw along pitch angle.yaw = 0; angle.pitch = 20; for (v = 0; v < 50; v++ ) { v1 = Location; v1 += Vector(angle) * len; DrawDebugLine(Location, v1, 0, 0,255); v2 = getPerpVectorTo(v1 - Location); DrawDebugLine(v1, v1 + v2, 255, 0, 0); angle.pitch += 20 * degtounrrot; } }

but for the dynamic version you should definitely use tick()

but you probably don't need to DrawPerps(), that was just for the video

have fun with your perpendicular lines for whatever your project is

~~~

**How to Draw Thick 3D Lines**Here's the code I use in the video for thick 3d lines

I wrote it all from scratch

Code:

//In your HUD class function drawThicker(vector v1, vector v2, color c, int PosFromCenter) { local vector start; local vector end; //so we can modify start = v1; end = v2; start.x += PosFromCenter; end.x += PosFromCenter; draw3DLine(start, end, c); start.y += PosFromCenter; end.y += PosFromCenter; draw3DLine(start, end, c); start.z += PosFromCenter; end.z += PosFromCenter; draw3DLine(start, end, c); start.x -= PosFromCenter*2; end.x -= PosFromCenter*2; draw3DLine(start, end, c); start.y -= PosFromCenter*2; end.y -= PosFromCenter*2; draw3DLine(start, end, c); start.z -= PosFromCenter*2; end.z -= PosFromCenter*2; draw3DLine(start, end, c); } function drawThickLine(vector v1, vector v2, color c, int thickness) { local int thickIncrement; //center of line draw3DLine(v1, v2, c); //draw surrounding layers of thickness from center for (thickIncrement = 1; thickIncrement <= thickness; thickIncrement++ ) { drawThicker(v1, v2, c, thickIncrement); } }

Code:

drawThickLine(v1,v2,makeColor(255,0,0),6);

**Summary**With this code you can find perpendicular lines / vectors in 3D space, given either just a vector, or a vector and an actor's Rotation!

Enjoy!

Rama

## Comment