Coding

 Reply to this postStart new topic

sines/cosines problem

hawk94
post Dec 8 2011, 12:14 AM
Post #1


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



Well.. i've posted this back into gtaforums but seems that there arent many responses there and as for my first post in this community i'll ask this...

ok, the thing is, that San andreas returns incorrect values when I get the sine of a yaw (upwards/downwards) angle that is about 20 degrees before and after 90 or 270 (-90) degrees of yaw... like if it has the resulting values "locked" to a max angle... this only happens with yaws, sines and cosines work well on Z angles... and by the way, the yaw is calculated properly so getting the angle is not the problem...

hope you can help me! thanks!!!


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Deji
post Dec 8 2011, 07:08 PM
Post #2


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



Show us some code to go on wink.gif


--------------------
Go to the top of the page
 
+Quote Post
hawk94
post Dec 8 2011, 09:52 PM
Post #3


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



QUOTE (Deji @ Dec 8 2011, 01:08 PM) *
Show us some code to go on wink.gif


Ok, here is my "tester":

CODE
{$VERSION 3.1.0027}
{$CLEO .cs}

//-------------MAIN---------------
0000: NOP

:Noname_2
0001: wait 0 ms
00D6: if and
0256:   player $PLAYER_CHAR defined
056D:   actor $PLAYER_ACTOR defined
004D: jump_if_false @Noname_2

:Noname_27
0001: wait 0 ms
00D6: if
00DF:   actor $PLAYER_ACTOR driving
004D: jump_if_false @Noname_27
0811: 0@ = actor $PLAYER_ACTOR car // versionC

:Noname_55
0001: wait 0 ms
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset -2.5 0.0 0.0
0407: store_coords_to 4@ 5@ 6@ from_car 0@ with_offset -2.5 1000.0 0.0
06BC: create_M4_shoot_from 1@ 2@ 3@ target 4@ 5@ 6@ energy 0
0174: 7@ = car 0@ Z_angle
0013: 7@ *= -1.0
077D: 8@ = car 0@ x_angle
02F6: 9@ = sine 7@ // (float)
02F7: 10@ = cosine 7@ // (float)
02F6: 11@ = sine 8@ // (float)
0013: 9@ *= 1000.0
0013: 10@ *= 1000.0
0013: 11@ *= 1000.0
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 2.5 0.0 0.0
0407: store_coords_to 4@ 5@ 6@ from_car 0@ with_offset 2.5 0.0 0.0
005B: 4@ += 9@ // (float)
005B: 5@ += 10@ // (float)
005B: 6@ += 11@ // (float)
06BC: create_M4_shoot_from 1@ 2@ 3@ target 4@ 5@ 6@ energy 0
00D6: if or
8256:   not player $PLAYER_CHAR defined
856D:   not actor $PLAYER_ACTOR defined
0119:   car 0@ wrecked
80DB:   not actor $PLAYER_ACTOR in_car 0@
004D: jump_if_false @Noname_55
01C3: remove_references_to_car 0@ // Like turning a car into any random car
0001: wait 1000 ms
0002: jump @Noname_2


Get on a car, and lean it upwards/downwards something like 90 degrees... you'll notice that one of the lines points the wrong way...


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Deji
post Dec 9 2011, 01:13 AM
Post #4


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



For starters...
CODE
077D: 8@ = car 0@ x_angle

should be
CODE
077D: 8@ = car 0@ y_angle


Your sascm.ini is outdated. Update it here. Then fix those problems and try again.


--------------------
Go to the top of the page
 
+Quote Post
hawk94
post Dec 9 2011, 04:14 AM
Post #5


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



QUOTE (Deji @ Dec 8 2011, 07:13 PM) *
For starters...
CODE
077D: 8@ = car 0@ x_angle

should be
CODE
077D: 8@ = car 0@ y_angle


Your sascm.ini is outdated. Update it here. Then fix those problems and try again.


I already knew that, getting the angle is not the problem, but getting the sine of the yaw yes...


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Deji
post Dec 9 2011, 04:32 PM
Post #6


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



What I don't get is why you even need sine/cosine for this. But if you want the first trail to follow the same 'yaw' as the other, just calculate the sine earlier and add it to the Z of that, too:
SANNY
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset -2.5 0.0 0.0
0407: store_coords_to 4@ 5@ 6@ from_car 0@ with_offset -2.5 1000.0 0.0
077D: 8@ = car 0@ x_angle
02F6: 11@ = sine 8@ // (float)
005B: 6@ += 11@ // (float)
06BC: create_M4_shoot_from 1@ 2@ 3@ target 4@ 5@ 6@ energy 0
0174: 7@ = car 0@ Z_angle
0013: 7@ *= -1.0
02F6: 9@ = sine 7@ // (float)
02F7: 10@ = cosine 7@ // (float)
0013: 9@ *= 1000.0
0013: 10@ *= 1000.0
0013: 11@ *= 1000.0
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 2.5 0.0 0.0
0407: store_coords_to 4@ 5@ 6@ from_car 0@ with_offset 2.5 1000.0 0.0
005B: 4@ += 9@ // (float)
005B: 5@ += 10@ // (float)
005B: 6@ += 11@ // (float)
06BC: create_M4_shoot_from 1@ 2@ 3@ target 4@ 5@ 6@ energy 0


Now they are both side by side at all times. But you could also do this just using 0407, without calculating the sine values.


--------------------
Go to the top of the page
 
+Quote Post
hawk94
post Dec 9 2011, 08:10 PM
Post #7


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



ok, I want the sine/cosine of the Z angle and the sine of the yaw because I did a script that creates a "shoot" from a cannon attached to the front of the car, and I need those values to get the direction towards where the "bullet" will fly (adding sines/cosine to the actual position of the "bullet", repeteadly until it reaches its destination)... you can check my mod here: http://anmzgtasamods.blogspot.com/2011/11/...defensa_26.html just activate it with Tab+K and shoot with backspace... then lean the car some degrees (near 90 or -90) upwards/downwards and shoot again... you'll see that the bullet now doesnt follow the correct direction... same with missiles (shoot them with secondary fire)....


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Deji
post Dec 10 2011, 02:41 PM
Post #8


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



The code I posted works fine, though... Is your problem solved?


--------------------
Go to the top of the page
 
+Quote Post
hawk94
post Dec 11 2011, 01:07 AM
Post #9


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



hmmm... no, its not solved yet... the problem is that I can't use 0407, as the point I want to get is not always 1000 m at the Y offset from my car... thats why I need the sine and cosine of the Z angle and the sine of the yaw... as the object will move periodically towards that point, no matter where the car is facing, once the "rocket" has been shot... I still can use 0407 to get those sines and the cosine but only for that... I hope I didnt mess you up.. hehe... by the way... did you test my mod???


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Deji
post Dec 11 2011, 10:10 AM
Post #10


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



In my code, I didn't mess with 0407.


--------------------
Go to the top of the page
 
+Quote Post
hawk94
post Dec 11 2011, 05:41 PM
Post #11


The New Guy!

Posts: 10
From: México
Joined: 8-December 11



no Im not saying that you messed in your code lol... by the way I think I've found what I was looking for here: wesser post

EDIT: I've solved this problem, thanks Deji!!!
In case you wonder: The thing was at the moment of getting the sines/cosines... the max distance (multiplier) must be multiplied by the cosine of the yaw, before affecting the sine and the cosine of the Z angle...

This post has been edited by hawk94: Dec 12 2011, 06:49 AM


--------------------
CLEO4 Mods by anmz // follow me!! @arielnmz
Go to the top of the page
 
+Quote Post
Reply to this postStart new topic

2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: