Quantcast

Jump to content

» «
Photo

Directional angle between 2 points (For Vice City)

5 replies to this topic
Jack
  • Jack

    wanted level modifications

  • Feroci
  • Joined: 06 Dec 2011
  • Serbia

#1

Posted 30 November 2013 - 02:14 PM

I'll let this picture to tell what exactly I need:
pkdnnyp1009adawfg.jpg
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 0@ 1@ and 2@ 3@ store_to 4@
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 13@ 14@ 15@ from_actor $PLAYER_ACTOR offset 0.0 200.0 30.0 
00A5: create_car #HUNTER at 13@ 14@ 15@ store_to 1@
009A: create_char 4 model #ARMY at 0.0 0.0 0.0 store_to 0@
0464: put_actor 0@ into_turret_on_car 1@ at_car_offset 0.0 0.0 0.0 position 0 angle 360.0 with_weapon 0
0337: set_actor 0@ visibility 0 
-------------------------------------------------------------------------------------------------------
WHILE TRUE
    wait 0
    04C4: create_coordinate 13@ 14@ 15@ from_actor $PLAYER_ACTOR offset 0.0 -25.0 30.0 
    04A2: heli 1@ fly_to 13@ 14@ 15@ speed 100
    020F: actor 0@ look_at_player $PLAYER_CHAR 
    0172: 2@ = actor 0@ z_angle 
    04D0: set_heli_orientation 1@ to 2@
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 :)

DK22Pac
  • DK22Pac

    Playing SA on my lovely PS2. Y'all bums.

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine

#2

Posted 30 November 2013 - 04:27 PM Edited by _DK, 30 November 2013 - 04:28 PM.

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

//...

05F7: 0@ = label @atan2 offset
05E1: call 0@ num_params 2 pop 2 _x 1@ _y 2@
05F2: 0@ = pop_float // pop result to 0@

//...

// float atan2(float y, float x)
:atan2
hex
    D9 44 24 04 // fld [esp+4]
    D9 44 24 08 // fld [esp+8]
    D9 F3       // fpatan
    C3          // retn
end
  • ThirteenAG likes this

NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#3

Posted 30 November 2013 - 04:41 PM

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


DK22Pac
  • DK22Pac

    Playing SA on my lovely PS2. Y'all bums.

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine

#4

Posted 30 November 2013 - 06:58 PM

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

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown

#5

Posted 30 November 2013 - 08:42 PM

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.0
end
var
    1@: Float
    2@: Float
    3@: Float
    4@: Float
    5@: Float
end
1@ = POINT_A_X
2@ = POINT_A_Y
3@ = POINT_B_X
4@ = POINT_B_Y
1@ -= 3@
2@ -= 4@
05A4: get_angle_between_2d_vectors 1@ 2@ and_origin_to 0.0 -1.0 store_to 5@
if
    1@ < 0.0
then
    5@ += -360.0
    5@ *= -1.0
end
  • Jack likes this

Jack
  • Jack

    wanted level modifications

  • Feroci
  • Joined: 06 Dec 2011
  • Serbia

#6

Posted 01 December 2013 - 12:12 PM Edited by Jack..., 01 December 2013 - 12:24 PM.

@_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 TRUE
wait 0
00AA: store_car 1@ position_to 5@ 6@ 0.0                // A
0054: store_player $PLAYER_CHAR position_to 13@ 14@ 0.0 // B
 
// vector 1
0063: 13@ -= 5@ // Xb-Xa
0063: 14@ -= 6@ // Yb-Ya
00AA: store_car 1@ position_to 5@ 6@ 0.0
02F7: cos 5@ store_to 7@   // x
02F6: sin 6@ store_to 8@   // y
0013: 7@ *= 120.0   // Xn (X-north)
0013: 8@ *= 120.0   // Yn (Y-north)
00AA: store_car 1@ position_to 5@ 6@ 0.0
 
// vector 2
0063: 7@ -= 5@ // Xn-Xa
0063: 8@ -= 6@ // Yn-Ya
05A4: get_angle_between_2d_vectors 13@ 14@ and_origin_to 7@ 8@ store_to 2@   // Directional Angle
04D0: set_heli_orientation 1@ to 2@
END
That did it. Thanks man :happy:.

 

The complexity simplifier, the efficiency optimizer.

Indeed :santa:.

  • Wesser likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users