Angles

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Three angle systems[edit | edit source]

The game uses three different angle ‘systems’:


World Angle[edit | edit source]

This is the most common. It is the angle you find in the CS for Reference Z Rotation.

Range – 0-360

If drawing in a piece of paper: 0 degrees is up, increasing clockwise up to 360. 90 = Right, 180 = Down, 270 = Left.

In a game worldspace: 0 degrees is North, increasing clockwise up to 360. 90 = East, 180 = South, 270 = West.

In a game interior: 0 degrees is North, as in the exterior, but considering North as you see it in the CS while editing an interior cell. Not the North pointed by the compass when you enter an interior in-game (this North is adjusted by the North Marker)

This type of angle is returned by: GetAngle Z, GetStartingAngle

This type of angle must be provided for: SetAngle Z


Heading Angle[edit | edit source]

This is used to tell how a second object is positioned in relation to a first object heading

Range – -180 to +180

0 degrees is up, increasing clockwise up to 180 and decreasing counterclockwise down to -180. 90 = Right, 180 = Down, -90 = Left, -180 = Down.

This type of angle is returned by: GetHeadingAngle


Trigonometric Angle[edit | edit source]

This is the standard trigonometric angle system.

Range – 0 to 360 - 0 degrees is right, increasing counterclockwise up to 360. 90 = Up, 180 = Left, 270 = Down.

This type of angle must be provided as arguments of OBSE trigonometric functions: Sin, Cos, Tan, etc


Sample code (2D)[edit | edit source]

DeltaX & DeltaY from Angle and distance[edit | edit source]

Useful when positioning an object at a given distance and angle from another object

;=================================
; Get:  DeltaX and DeltaY
; From:	Angle and distance
;=================================
set xAngle to <some angle>
set xDistance to <some distance>
if  xAngle <= 90
  set xTrigAngle  to 90 - xAngle
else
  set xTrigAngle to 450 - xAngle
endif 
set xDeltaX to xDistance * cos xTrigAngle 
set xDeltaY to xDistance * sin xTrigAngle 


Angle and distance from DeltaX & DeltaY[edit | edit source]

Useful to calculate the horizontal (2D) distance between two objects or in situations where GetDistance is not reliable.

Useful to calculate the heading angle in situations where GetHeadingAngle is not reliable (non-actors).

;=================================
; Get:  Angle and distance
; From: DeltaX and DeltaY
;=================================
set xAngle to atan2 xDeltaX xDeltaY   	;	returns -180 to +180
if xAngle  < 0
  set xAngle to xAngle + 360   		;	convert to 0-360
endif

set xDistance to ( xDeltaX * xDeltaX ) + ( xDeltaY * xDeltaY )
set xDistance to sqrt xDistance


Adding two angles[edit | edit source]

Self explanatory

;=================================
; Get:  Angle 
; From: Adding two angles
;=================================
set xAngle to xAngleA + xAngleB
if xAngle > 360
  set xAngle to xAngle - 360
elseif xAngle < 0
  set xAngle to xAngle + 360
endif