Jump to content

Object Rotation Velocity


12jango

Recommended Posts



{$CLEO .cs}




thread 'sweat'




:LOAD
wait 0
Model.Load(615)
Model.Load(#NULL)
if and
Model.Available(615)
Model.Available(#NULL)
jf @LOAD




:TRI
wait 0
if and
Player.Defined($PLAYER_CHAR)
0AB0: key_pressed 49
jf @TRI
04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 3.0 5.0
04C4: store_coords_to 14@ 15@ 16@ from_actor $PLAYER_ACTOR with_offset 13.0 3.0 5.0
0@ = Object.Create(615, 11@, 12@, 13@)
20@ = Object.Create(615, 14@, 15@, 16@)




:TO
wait 0
Object.Angle(0@) = 0.0
Object.Angle(20@) = 0.0
if and
Player.Defined($PLAYER_CHAR)
0AB0: key_pressed 50
jf @TO




:wAN
wait 0
0400: store_coords_to 1@ 2@ 3@ from_object 0@ with_offset 0.0 0.0 0.0
// Movement velocity
27@ = 0.02
33@ = 77.0
// Get the in-between vector
0063: 4@ -= 1@
0063: 5@ -= 2@
0063: 6@ -= 3@
// Calculate vector length
050A: 28@ = distance_between_XYZ 0.0 0.0 0.0 and_XYZ 4@ 5@ 6@
// Get the unit vector
0073: 4@ /= 28@
0073: 5@ /= 28@
0073: 6@ /= 28@
// Multiply the vector by velocity
006B: 4@ *= 27@
006B: 5@ *= 27@
006B: 6@ *= 27@
// Calculate the angle between the 2 points
05A1: set_object 0@ rotation_velocity_about_an_axis 4@ 5@ 6@ through_center_of_body




05A6: get_object 0@ rotation_velocity_about_an_axis_X 4@ axis_Y 5@ axis_Z 6@ through_center_of_body
0453: set_object 20@ XY_rotation 4@ 5@ angle 6@
jump @WAN



Just a simple script; press 1 to spawn two trees in front of you then press 2 to rotate one tree.


It supposed to rotate both tree, but it's only one tree rotating (object 0@), I tried to rotate the other tree (object 20@) by using opcode 05A6 first then use 0453 to rotate it but didn't work! :rol:


So, what does opcode 05A6 use for? I thought it would get an object rotation so you can use it to set another object's rotation to be same as the one you get? :/


Edited by 12jango
Link to comment
Share on other sites

You wrote $20@. SB oddly accepts this big syntactical incongruity and treats it as a local variable with a hexadecimal identifier (32@).

Edited by Wesser
Link to comment
Share on other sites

I'm sorry I made mistakes when typing the script especially the $20@ I meant it 20@. :blush:

This time is the correct one. If you have time, please try it out to see what this script do.

The tree on your right is the object 20@ that won't rotating. :turn:

Link to comment
Share on other sites

Is there any way to use 05A6:?

Edited by 12jango
Link to comment
Share on other sites

You wrote $20@. SB oddly accepts this big syntactical incongruity and treats it as a local variable with a hexadecimal identifier (32@).

huh, funny :p should I fix that or leave it alone as a one yet feature?

Link to comment
Share on other sites

huh, funny :p should I fix that or leave it alone as a one yet feature?

Maybe tweak it so it's less ambiguous and allow hex for globals too?

Link to comment
Share on other sites

It is not bad at all. I would suggest to clear the ambiguity with a percent sign (%).

Link to comment
Share on other sites

What about

 

$0x20 - global variable with ID 320x20@ - local variable with ID 32
Edited by fastman92
Link to comment
Share on other sites

It will be still ambiguous as x and X are valid characters for defining custom globals names. Adding a special character right after the dollar sign ($) or before the local ID will easily advert SB to treat everything following (till another distinguishing token) as a hexadecimal number.

Edited by Wesser
Link to comment
Share on other sites

Ok, true.

Link to comment
Share on other sites

GTA scripts have too much data types characters already, so I would not add a one yet as the proposed percent sign.

 

The common convention for the variables naming is that the names must not begin with a digit. So $0x10 is not a valid name.

In fact SB threats it as a hexadimal value and compiles $0x10 as $16. Similarly, 0x10@ will be compiled as 16@. It means that the fastman's way is already implemented.

 

$20@ definitely should be reported as an error by the compiler (and it looks so, two data types characters in one token are used).

Link to comment
Share on other sites

Yes, my bad, SB behaves like most compilers do indeed. Didn't know about the way of representing variables indices in hexadecimal. I totally agree with you then.

Link to comment
Share on other sites

So you're saying 05A6: isn't working at all?

Edited by 12jango
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.