Welcome to GTAForums! Be sure to check out the GTA San Andreas forum. If you haven't already, register - it's fast, it's free and it's easy. ( Log In | Register | Revalidate Validation E-mail )

Making objects rotate, Figured it out

 Y_Less Posted: Oct 18 2004, 10:03 Vice State Leader Group: Members Joined: Mar 14, 2004 OK, I have been working on this problem for a while now. I didn't just want something to spin on the spot, I wanted it to actually go in a circle around a point, i.e.:(IMG:http://www.y-less.com/images/others/circle1.GIF)As far as I could find, there was no suitable OpCode. I tried a number of ways including using the SINE and COSINE OpCodes to calculate the points on the circle, but this was insanely complex. I tried using the new Path OpCodes and writing the path in a file but this isn't very custmisable and also hard and I eventually gave up.Then yesterday I had this idea (I don't have any code ATM, i'm working on it, but i'll post it here when its done). It is very easy and I cn't believe I missed it:1) Create the object you want to rotate and another object in the centre of its circle (height doesn't matter, you can hide it underground or show it, i.e. a crane rotating with a car (what I originally wanted this for)).2) Rotate the cenral object using 834D (one I found - see page 6 of the OpCodes thread).3) Create an offset co-ordinate from the central object, the radius of your circle (I always assumed this was absolute, but found out it was relative yesterday, i.e. depends on the angle of the object). If your centre object is hidden, you can use this to modify the height.4) Place your circling object at this point.5) You can either set the angle to an absolute (i.e. 0) or an angle relative to the central thing so it looks like its properly going in a circle. This is fairly easy. This post has been edited by Y_Less on Oct 18 2004, 10:12

Opius
Posted: Oct 18 2004, 10:17

Opius

Group: NYCC Moderator
Joined: Jun 27, 2002

I used this to create a ring of explosions. This one was more sort of a "look-what-I-can-do-with-the-power-of-MATHS" display, but yours looks like it works just as well.

 CODE 0407: create_coordinate 0@ 1@ 2@ from_car 3@ offset  0.0 0.0 0.0\$explosion_angle = 5.0\$explosion_radius = 5.0:barrel_first_maths008A: \$explosionX = 0@008A: \$explosionY = 1@0009: \$explosion_angle +=  15.0 ;; floating-point values (never used in VC or GTA 3)008A: \$explosion_angle2 = \$explosion_angle000D: \$explosion_angle2 -=  90.0 ;; floating-point values  00D6: if  00032:    0.0 >=  \$explosion_angle2 ;; floating-point values004D: jump_if_false ££barrel_second_maths  0009:  \$explosion_angle2 +=  180.0 ;; floating-point values :barrel_second_maths02F7: 3@ = sinus  \$explosion_angle;; cosine swapped with sinus02F6: 4@ = cosine \$explosion_angle ;; sinus swapped with cosine 0069: 3@ *= \$explosion_radius ;; floating-point values0069: 4@ *= \$explosion_radius ;; floating-point values0011: 3@ *= -1.0 ;; stupid stupid backwards nubmers stab stab stab0011: 4@ *= -1.0      0009:  \$explosionX += 3@ ;; floating-point values0009:  \$explosionY += 4@ ;; floating-point values020C: create_explosion_with_radius  1 at  \$explosionX \$explosionY  2@ 0001: wait  100 ms000A: \$loops +=  1 ;; integer values00D6: if  00039:   \$loops ==  24 ;; integer values004D: jump_if_false ££barrel_first_maths

 PatrickW Posted: Oct 18 2004, 10:20 GTA Juggernaut Group: Members Joined: Jan 7, 2004 Y_less, great brainwave !!! It's to simple to be wrong. :cookie:

 Y_Less Posted: Oct 18 2004, 10:22 Vice State Leader Group: Members Joined: Mar 14, 2004 I had something like that originally, using maths to work it out, but it was a bit awkward.Edit: Patrick, thanks, I was just playing with the water jump mod from 1.3 (where pressing a button spawns one in front of you), and realised that the co-ordinates generated must be relative to your direction, not just your position as I had assumed before.

 PatrickW Posted: Oct 18 2004, 10:32 GTA Juggernaut Group: Members Joined: Jan 7, 2004 You are so right, this will be more smoother and a lot less code,let the engine perform the trig. , I bet it can do it much faster as from scm code.I'm looking forward for your demonstration :)

 Y_Less Posted: Oct 18 2004, 11:02 Vice State Leader Group: Members Joined: Mar 14, 2004 i'm at school atm, but i'll write it tonight (unless I can find a copy of the .SCM or OpCodes here) and post it tomorrow.

Y_Less
Posted: Oct 19 2004, 09:48

Group: Members
Joined: Mar 14, 2004

OK, done it.

This is just a basic one, once youve got this, its dead easy.

A few points:

1) Because of the way 834D works, you need 3 points to rotate to. Just 1 and it will rotate the shortest way to it, 2 (i.e. 0 and 180) and it will oscillate, it doesn't go in a circle. So for this I used 60, 180 and 300 (don't ask why).

I have included 2 methods, 1 for cars, one for objects.

Setup:

This is for the central object:

 CODE 029B: \$spinningcentre = init_object -36? (CI_BACKGATECLOSE) at 258! -416! 11!   0177: set_object \$spinningcentre z_angle_to  180!01C7: spawn_object \$spinningcentre

Setting up a car (this bit isn't needed, its just for the example, this could be anywhere in you script):

 CODE 0247: request model #DELUXO:Labelrequest1  0001: wait  0? ms00D6: if  0?  0248:   model #DELUXO available004D: jump if false ££Labelrequest100A5:  \$spinningthing = create car #DELUXO at 258! -416! 14!

Same again for objects:

 CODE 029B: \$spinningthing = init_object -91? (BODYARMOUR) at 258! -416! 11!   0177: set_object \$spinningthing z_angle_to  180!01C7: spawn_object \$spinningthing

 CODE :Labelspinning103A4: name_thread "spin"0007:  6@ =  300!  \\ floating-point values :Labelspinning20001: wait  10? ms00D6: if  0?  834D: NOT unknown rotate object  \$spinningcentre unknown angle  6@  1!  0?004D: jump_if_false ££Labelspinning30400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!0176:  4@ = object  \$spinningcentre z angle

For objects:

 CODE 01BC: put object  \$spinningthing at  1@ 2@ 3@0177: set_object \$spinningthing z_angle_to  4@

For cars:

 CODE 00AB: put_car  \$spinningthing at  1@ 2@ 3@0175: set_car  \$spinningthing z_angle_to  4@

 CODE 0002: jump ££Labelspinning2:Labelspinning3    000B:  6@ +=  120!  \\ floating-point values00D6: if  0?  0021:    6@ >  360!  \\ floating-point values004D: jump if false ££Labelspinning2000F:  6@ -=  360!  \\ floating-point values0002: jump ££Labelspinning2

When activated (in this case from the beginning) the middle object will rotate to angle 6@, by 1 degree angles, every 10ms, when it reaches that point the code jumps to Labelspinning3 which modifies 6@, keeping it in the range 0 - 360, so it doesn't go too high.

Examples:

Object:

(IMG:http://www.y-less.com/vc/treem.jpg)

Car:

(IMG:http://www.y-less.com/vc/carm.jpg)

(They are going in circles, trust me).

New untested brainwave: If you set 6@ to say 720 and the object to 0, I don't know how clever it is, it may not move or it may go round twice, it generally takes the shortest path but i've never tested this OpCode with values over 360.

Y_Less
Posted: Oct 27 2004, 17:57

Group: Members
Joined: Mar 14, 2004

*BUMP, soz*

I have been playing about with this effect and have developed a few things which I decided to add here. (I added a reply instead of an edit so it came up with a new post).

1. Multiple cars.

This isn't hard really, I just made the central thing rotate by a little bit, then spin very fast placing cars around the edge of its circle.

Example for 2 cars:

Setup:

 CODE 029B: \$spinningcentre = init_object -36? (MASK) at -1060! -930! 20!   0177: set_object \$spinningcentre z_angle_to  180!01C7: spawn_object \$spinningcentre    0247: request model #DELUXO:Labelrequest1  0001: wait  0? ms00D6: if  0?  0248:   model #DELUXO available004D: jump if false ££Labelrequest100A5:  \$spinningthing = create car #DELUXO at -1060! -930! 20!00A5:  \$spinningthing2 = create car #DELUXO at -1060! -930! 25!

 CODE :Labelspinning103A4: name_thread "spin"    0007:  6@ =  300!  \\ floating-point values :Labelspinning2 0001: wait  10? ms00D6: if  0?  834D: NOT unknown rotate object  \$spinningcentre unknown angle  6@  1!  0?004D: jump_if_false ££Labelspinning30176:  4@ = object  \$spinningcentre z angle 0176:  5@ = object  \$spinningcentre z angle 000B:  4@ +=  180!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!00AB: put_car  \$spinningthing at  1@ 2@ 3@0175: set_car  \$spinningthing z_angle_to  0!000B:  4@ +=  180!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!00AB: put_car  \$spinningthing2 at  1@ 2@ 3@0175: set_car  \$spinningthing2 z_angle_to  0!0177: set_object \$spinningcentre z_angle_to  5@0002: jump ££Labelspinning2:Labelspinning3    000B:  6@ +=  120!  \\ floating-point values00D6: if  0?  0021:    6@ >  360!  \\ floating-point values004D: jump if false ££Labelspinning2000F:  6@ -=  360!  \\ floating-point values0002: jump ££Labelspinning2

This rotates the axis a little then rotates it (360 / number of cars), places the first car at an offset, rotates it again till all the cars are placed, then returns it to its original angle to continue the slight rotation.

I rotate it more before the first car so by the end you know it is 360 out from where it was originally, and so all the bits of code look the same so if you wanted you could use an array code and not need to modify anything else. (Also I originally had it so at the end the angle was decreased by 360, but recording and resetting the angle is more reliable).

(In this picture I tested getting in the cars and it still goes fine).

(IMG:http://www.y-less.com/vc/2carflm.jpg)

2. Vertical Spinning.

This requires a bit of trickery, it does rotate them up, like a ferris wheel, but, as you know, you cannot rotate the central item vertically. So this is what you do:

Decide the centre of the wheel co-ordinate, e.g. 392.0 300.0 12.4 (completely random) then put your central item at 329.0 (x) 12.4 (z) 20.0 - note which numbers are the same and where they are.

Then use this code (exapmle for 1):

Setup:

 CODE 029B: \$spinningcentre = init_object -36? (MASK) at -1060! 20! 0!   0177: set_object \$spinningcentre z_angle_to  180!01C7: spawn_object \$spinningcentre    0247: request model #DELUXO:Labelrequest1  0001: wait  0? ms00D6: if  0?  0248:   model #DELUXO available004D: jump if false ££Labelrequest100A5:  \$spinningthing = create car #DELUXO at -1060! -930! 20!00A5:  \$spinningthing2 = create car #DELUXO at -1060! -930! 25!

 CODE :Labelspinning103A4: name_thread "spin"    0007:  6@ =  300!  \\ floating-point values :Labelspinning2 0001: wait  10? ms00D6: if  0?  834D: NOT unknown rotate object  \$spinningcentre unknown angle  6@  1!  0?004D: jump_if_false ££Labelspinning3

The important bit:

 CODE 0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000B:  3@ +=  280!  \\ floating-point values (difference between 20.0 and 300.0)00AB: put_car  \$spinningthing at  1@ 3@ 2@ \\ Very important order of variables!

This means the car is going around in a circle as normal, but 2 of the axes are switched (with a bit of alteration as the engine doesn't like a z co-ordinate of 300.0).

Rest of the code:

 CODE 0175: set_car  \$spinningthing z_angle_to  0!0002: jump ££Labelspinning2:Labelspinning3    000B:  6@ +=  120!  \\ floating-point values00D6: if  0?  0021:    6@ >  360!  \\ floating-point values004D: jump if false ££Labelspinning2000F:  6@ -=  360!  \\ floating-point values0002: jump ££Labelspinning2

Example for 8 cars (yes 8, it looks very silly!) (same setup but for 8 cars):

 CODE :Labelspinning103A4: name_thread "spin"    0007:  6@ =  300!  \\ floating-point values :Labelspinning2 0001: wait  10? ms00D6: if  0?  834D: NOT unknown rotate object  \$spinningcentre unknown angle  6@  1!  0?004D: jump_if_false ££Labelspinning30176:  4@ = object  \$spinningcentre z angle 0176:  5@ = object  \$spinningcentre z angle 000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing at  1@ 3@ 2@0175: set_car  \$spinningthing z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing2 at  1@ 3@ 2@0175: set_car  \$spinningthing2 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing3 at  1@ 3@ 2@0175: set_car  \$spinningthing3 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing4 at  1@ 3@ 2@0175: set_car  \$spinningthing4 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing5 at  1@ 3@ 2@0175: set_car  \$spinningthing5 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing6 at  1@ 3@ 2@0175: set_car  \$spinningthing6 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing7 at  1@ 3@ 2@0175: set_car  \$spinningthing7 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values00AB: put_car  \$spinningthing8 at  1@ 3@ 2@0175: set_car  \$spinningthing8 z_angle_to  0!0177: set_object \$spinningcentre z_angle_to  5@0002: jump ££Labelspinning2:Labelspinning3    000B:  6@ +=  120!  \\ floating-point values00D6: if  0?  0021:    6@ >  360!  \\ floating-point values004D: jump if false ££Labelspinning2000F:  6@ -=  360!  \\ floating-point values0002: jump ££Labelspinning2

(IMG:http://www.y-less.com/vc/verts.jpg)

3. Ovals.

This is fairly basic once you have the rest of it understood. It is just a bit of maths, finding the cars offset in one axis from the centre and reducing it a bit (e.g. halfing it). You just need to know the ratio of x to y axes you will be using (in this example 2:1) and remember that the larger number will be the actual radius of your circle (you could increase instead, but this method doesn't).

Example:

Setup same as above (for 8 vertical cars).

 CODE :Labelspinning103A4: name_thread "spin"    0007:  6@ =  300!  \\ floating-point values :Labelspinning2 0001: wait  10? ms00D6: if  0?  834D: NOT unknown rotate object  \$spinningcentre unknown angle  6@  1!  0?004D: jump_if_false ££Labelspinning30176:  4@ = object  \$spinningcentre z angle 0176:  5@ = object  \$spinningcentre z angle

The important bit again:

 CODE 000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3) - NOTE: DOES WORK - IVE TESTED IT!000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing at  7@ 3@ 2@0175: set_car  \$spinningthing z_angle_to  0!

As you can see, 7@ = 1@, it is then reduced to find the offset from 0 (-1060!), the difference is the halfed and then the whole lot is brought back up.

 CODE 000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing2 at  7@ 3@ 2@0175: set_car  \$spinningthing2 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing3 at  7@ 3@ 2@0175: set_car  \$spinningthing3 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing4 at  7@ 3@ 2@0175: set_car  \$spinningthing4 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing5 at  7@ 3@ 2@0175: set_car  \$spinningthing5 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing6 at  7@ 3@ 2@0175: set_car  \$spinningthing6 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing7 at  7@ 3@ 2@0175: set_car  \$spinningthing7 z_angle_to  0!000B:  4@ +=  45!  \\ floating-point values0177: set_object \$spinningcentre z_angle_to  4@0400: create coordinate  1@ 2@ 3@ from object  \$spinningcentre offset 10! 0! 5!000F:  3@ -=  930!  \\ floating-point values0087:  7@ =  1@  \\ floating-point values only000F:  7@ -=  -1060!  \\ floating-point values0017: 7@ /= 2!  \\ floating-point values (never used in VC or GTA 3)000B:  7@ +=  -1060!  \\ floating-point values00AB: put_car  \$spinningthing8 at  7@ 3@ 2@0175: set_car  \$spinningthing8 z_angle_to  0!0177: set_object \$spinningcentre z_angle_to  5@0002: jump ££Labelspinning2:Labelspinning3    000B:  6@ +=  120!  \\ floating-point values00D6: if  0?  0021:    6@ >  360!  \\ floating-point values004D: jump if false ££Labelspinning2000F:  6@ -=  360!  \\ floating-point values0002: jump ££Labelspinning2

I don't know how clear this is, but I have tested it and it all works (although obviously with 8 cars it stops standard spawning, but it looks funny), and with a few Op-Code changes (shown in an earlier post) it can be modified for models.

(IMG:http://www.y-less.com/vc/ovalum.jpg)

Random other pictures.

Cars and tanks:

(IMG:http://www.y-less.com/vc/carntnkm.jpg)

More Ovals:

(IMG:http://www.y-less.com/vc/ovalm.jpg)

(IMG:http://www.y-less.com/vc/verts.jpg)

 Opius Posted: Oct 27 2004, 21:54 Opius Group: NYCC Moderator Joined: Jun 27, 2002 Holy sh*t! That's amazing. Thanks for sharing. :)

 Y_Less Posted: Oct 29 2004, 10:28 Vice State Leader Group: Members Joined: Mar 14, 2004 Thanks for the feedback.And thanks alot Opius :cookie: :D .I forgot to mention this earlier (This only applies on the circular one)To find the speed of rotation:x = x offsety = y offsett = delay in ms in your loopz = total ofset (sqr(x² + y²))d = degrees turned each timec = circumferences = speedBasic calculation:s = d/(t/1000) (degrees per second)For distance:Using s = d/(t/1000)and c = 2PIrr = z:. c = 2PIzsegment = 2PIz/(360/d)for speed:s = 2PIz/(360/d)/(t/1000) (units per second)

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