Search In
• More options...
Find results that contain...
Find results in...

# Directional angle between 2 points (For Vice City)

## Recommended Posts

I'll let this picture to tell what exactly I need:

So I need the angle between the north line and AB line. As most of you already know there're no opcode for the invert function of tangens in Vice City.

I've only found this one:

`05A4: get_angle_between_2d_vectors [email protected] [email protected] and [email protected] [email protected] store_to [email protected]`

It doesn't calculate arctg but arccos instead.

Why do I need this directional angle:

I want to force any moving helicopter to look directly at players car all the time no matter which coordinates it has. I've tried a simple method:

`-----------------------------------------------------------------------------04C4: create_coordinate [email protected] [email protected] [email protected] from_actor \$PLAYER_ACTOR offset 0.0 200.0 30.0 00A5: create_car #HUNTER at [email protected] [email protected] [email protected] store_to [email protected]009A: create_char 4 model #ARMY at 0.0 0.0 0.0 store_to [email protected]0464: put_actor [email protected] into_turret_on_car [email protected] at_car_offset 0.0 0.0 0.0 position 0 angle 360.0 with_weapon 00337: set_actor [email protected] visibility 0 -------------------------------------------------------------------------------------------------------WHILE TRUE    wait 0    04C4: create_coordinate [email protected] [email protected] [email protected] from_actor \$PLAYER_ACTOR offset 0.0 -25.0 30.0     04A2: heli [email protected] fly_to [email protected] [email protected] [email protected] speed 100    020F: actor [email protected] look_at_player \$PLAYER_CHAR     0172: [email protected] = actor [email protected] z_angle     04D0: set_heli_orientation [email protected] to [email protected]END`

Well this do trick but only aproximately - I need a precise direction.

I'm starting to think that heli speed or maybe a mass has something to do with this problem.

Any suggestions? Thanks .

##### Share on other sites

http://en.wikipedia.org/wiki/Atan2

`//...05F7: [email protected] = label @atan2 offset05E1: call [email protected] num_params 2 pop 2 _x [email protected] _y [email protected]: [email protected] = pop_float // pop result to [email protected]//...// float atan2(float y, float x):atan2hex    D9 44 24 04 // fld [esp+4]    D9 44 24 08 // fld [esp+8]    D9 F3       // fpatan    C3          // retnend`
Edited by _DK

##### Share on other sites

oh yeah, let's use non-standard commands provided by a runtime with disputed stability and mix code with data

##### Share on other sites

And let's play un-modded GTA games also.

##### Share on other sites

If you want to deal with GET_ANGLE_BETWEEN_2D_VECTORS (05A4) command, you should be capable to distinguish a vector by a point. A vector simply describes the direction pointing to a point. The mentioned command needs 2 points rotating around a third point to behave like SA's GET_HEADING_FROM_VECTOR_2D (0604) command:

`const    POINT_A_X = 0.0    POINT_A_Y = 0.0    POINT_B_X = -1.0    POINT_B_Y = 0.0endvar    [email protected]: Float    [email protected]: Float    [email protected]: Float    [email protected]: Float    [email protected]: [email protected] = [email protected] = [email protected] = [email protected] = [email protected] -= [email protected]@ -= [email protected]: get_angle_between_2d_vectors [email protected] [email protected] and_origin_to 0.0 -1.0 store_to [email protected]    [email protected] < 0.0then    [email protected] += -360.0    [email protected] *= -1.0end`

##### Share on other sites
@_DK I'm not really into that hardcoded things right now so I'll take Wessers method. But thanks for the help. I'll look into it latter.
@Wesser:
`WHILE TRUEwait 000AA: store_car [email protected] position_to [email protected] [email protected] 0.0                // A0054: store_player \$PLAYER_CHAR position_to [email protected] [email protected] 0.0 // B // vector 10063: [email protected] -= [email protected] // Xb-Xa0063: [email protected] -= [email protected] // Yb-Ya00AA: store_car [email protected] position_to [email protected] [email protected] 0.002F7: cos [email protected] store_to [email protected]   // x02F6: sin [email protected] store_to [email protected]   // y0013: [email protected] *= 120.0   // Xn (X-north)0013: [email protected] *= 120.0   // Yn (Y-north)00AA: store_car [email protected] position_to [email protected] [email protected] 0.0 // vector 20063: [email protected] -= [email protected] // Xn-Xa0063: [email protected] -= [email protected] // Yn-Ya05A4: get_angle_between_2d_vectors [email protected] [email protected] and_origin_to [email protected] [email protected] store_to [email protected]   // Directional Angle04D0: set_heli_orientation [email protected] to [email protected]`
That did it. Thanks man .

The complexity simplifier, the efficiency optimizer.

Indeed .

Edited by Jack...

## Create an account

Register a new account