Jump to content

Rotating objects 2


Recommended Posts

First, readthis.

 

Right, I thought of this possibly nearly a year ago, but never posted it cos I could never be bothered to write a full tutorial, I still can't but I'm going to shove the basics in your face.

 

It is an update to my rotating objects topic, there were limitations with it meaning you could only rotate on one axis, or another with VERY limited options.

 

Then, about a week later, I found this OpCode (it is, as guessed there set_object_rotation), and the code suddenly became alot better.

 

Basically you do what I did for one axis in the original thread for ALL the axies with this new one (or which ever ones you want to rotate on). You don't even need to rotate fully, you could just make it bob up and down while rotating or do any one of a number of things.

 

I was very keen to make a fairground mod where all the rides (I thought up lots to code, some pretty good (including a rollercoaster with full physics - could be good for Myriad, especially with the new island to fill)) but I could never get a modeller onto it enough to get models.

 

But yeah, I had loads of code snippetsfor it doing odd things, but I'm not sure where they are atm, or even if they're on this laptop.

Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/
Share on other sites

Right, I'm sat in a programming lab supposed to be writing a java code framework from a UML diagram, that's not happening so I decided to update this as no-one seems to have paid it any attention. Note: as I am at uni atm, there are no images to demostrate it. I will then include some example code at the end (note again: as I am in uni I have no code on me so it will all be untested but should work, I can still remember what I did).

 

Basic Principles.

 

When you use "0400: $x $y $z get_point_on_object_plane $object offset $xoffset $yoffset $zoffset" the co-ordinate generated is RELATIVE to the original object POSITION AND ANGLE. So an offset of 5.0 0.0 0.0 will create a co-ordinate 5.0 DIRECTLY AHEAD of the object, not 5.0 along the x-axis from it.

 

Therefore if your object is rotating and you create an offset straight in front of it, it will be positioned at some point along a circle, radius offset, centre original object. This was how the old version worked in 2D using some OpCodes, this version has been updated to use better ones.

 

Basic Code.

 

 

004F: create_thread ££rotate000

 

 

 

:rotate00003A4: name_thread "rotate" // OK, I had to look this line up0247: request_model #waterjump // Find your own model to use0247: request_model #uzi // Lets make a gun the centre (best to use an invisible model but I don't have one)038B: load_requested_models // I'm disturbed that I've coded up to here purely from memory:rotate0010001: wait 10 ms00D6: if 10248:   model #waterjump loaded0248:   model #uzi loaded004D: jump_if_false ££rotate0010107: $centreobj = create_model #uzi at 100.3 420.6 12.6 // Can't guarantee the co-ordinates are good0107: $rotateme = create_model #waterjump at 0.0 0.0 0.00249: release_model #uzi0249: release_model #waterjump0005: $zrot = 0.0:rotate002:0001: wait 50 ms // This is the start of the main control loop.  The delay here helps set speed.0453: set_object $centreobj rotation 0.0 0.0 $zrot0400: $x $y $z get_point_on_object_plane $centreobj offset 10.0 0.0 0.001BC: put_object $rotateme at $x $y $x0086: $nurot = $zrot0009: $nurot += 90.00177: set_object $ rotateme rotation $nurot0009: $xrot += 10 // This angle will also help determine speed and granuality00D6: if 00030:   $zrot > 360.0004D: jump_if_false ££rotate002000D: $zrot -= 360.00002: jump ££rotate002

 

 

Thats just a basic code to move a waterjump round in a basic circle, facing in the direction of travel (thats what the $nurot part did). There are obviously improvements that could be made to the code, not using globals everywhere, using less variables etc but that is a basic code. It also at the end limits $xrot so it stays within standard degrees.

 

You can also change the 3D point on the plane you are getting the co-ordinates from, so a line of:

 

 

0400: $x $y $z get_point_on_object_plane $centreobj offset 10.0 0.0 5.0

 

 

Will set the waterjump onto a circle 5.0 units above the centre object with still the same radius. If you changed the other angles you will get some wierd effects if you use them together. If you just want to make something rotate vertically like a ferris wheel, just alter the x angle. Altering the y axis makes things rotate about their longitudinal axis (y rotation is also known as roll, x = pitch, z = yaw: pitch, roll, yaw) so an offset straight infront of the centre object will not move the moving object at all.

 

Some bits of code for fairground rides. I did want to release these myself with the aid of a modeller, but it never happened. It could have been a very interesting Myriad lot (quite a big one too).

 

Ferris wheel.

 

This ferris wheel has 8 cars which all stay upright as the wheel turns, adding more is easy as the code is designed to be expanded. Note: this code assumes $fwcar([0-9]+), $fwwheel and $fwcenter are already set up as a correctly loaded models. $fwcar([0-9]+) is the ferris wheel car model, $fwwheel is the ferris wheel and $fwcenter is an invisible model at the centre of the wheel used to place all the cars. You can if you want easilly replace the globals with floats, save space, it may even be recommended, I just cba again, I use them occasionally.

 

 

:labelferris1000005: $fwxangle = 45.0 // Initial angle of the ferris wheel0005: $fwyangle = 0.0 // Initial TILT of the wheel, alter it if you REALLY want0005: $fwzangle = 90.0 // Initial direction of the ferris wheel0005: $fwradius = 30.0 // Radius of ferris wheel, set to yours0004: $fwwait = 10 // Delay in ms0005: $fwspeed = 5.0 // Angle to increment by each step0005: $fwcars = 8 // Change to add more cars, they will be placed automatically but you will need to add them to the list, I couldn't be bothered to use my own arrays (they're so hard to implement even I can't be arsed!)0002: jump ££labelferris110// List of cars part one (add your extras to both):labelferris1010084: $fwcar = $fwcar00051: return0084: $fwcar = $fwcar10051: return0084: $fwcar = $fwcar20051: return0084: $fwcar = $fwcar30051: return0084: $fwcar = $fwcar40051: return0084: $fwcar = $fwcar50051: return0084: $fwcar = $fwcar60051: return0084: $fwcar = $fwcar70051: return// Part 2:labelferris1020084: $fwcar0 = $fwcar0051: return0084: $fwcar1 = $fwcar0051: return0084: $fwcar2 = $fwcar0051: return0084: $fwcar3 = $fwcar0051: return0084: $fwcar4 = $fwcar0051: return0084: $fwcar5 = $fwcar0051: return0084: $fwcar6 = $fwcar0051: return0084: $fwcar7 = $fwcar0051: return// You don't need to change owt below here.:labelferris1100093: 0@ = int_to_float $fwcars0005: $fwcarang = 360.00077: $fwcarang /= 0@:labelferris1200001: wait $fwwait0084: $fwloop = $fwcars0010: $fwloop *= 100453: set_object $fwwheel angle $fwxangle $fwyangle $fwzangle0453: set_object $fwcenter angle $fwxangle $fwyangle $fwzangle0089: 4@ = $fwzangle:labelferris1250004: $fwget = ££labelferris1010004: $fwset = ££labelferris1020008: $fwget += $fwloop0008: $fwset += $fwloop0050: gosub $fwget0400: 0@ 1@ 2@ get_point_on_object_plane $fwcenter $fwradius 0.0 0.0// Not sure about the parameter order, I'm using the DB here and it's different to MB which I'm coding in if you hadn't noticed.01BC: put_object $fwcar at 0@ 1@ 2@0051: gosub $fwset005D: 4@ += $fwcarang0453: set_object $fwcenter angle $fwxangle $fwyangle 4@000C: $fwloop -= 1000D6: if 00030:   $fwloop > 0004D: jump_if_false ££labelferris1200002: jump ££labelferris125

 

 

Thats all you're getting for now, if I can be arsed I may give you more code for more bits. That code should work but it's done from memory so don't blame me if it doesn't. It doens't reference the player so doesn't have a definition check, if you want to add one, go for it. It is also designed for extensibility over speed so if you know exactly how many cars you will always want to do you can modify it to be much better for only that number (remove all the lookup tables etc). Also with a little modification this can be modded to run ALL your ferris wheels (should you want lots) to save on code space.

Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3371613
Share on other sites

random_download

Nice, this would be a great addition to Myriad tounge.gif

 

Few things: first, I think that at the end of your code where you have "0030: $fwloop > 0" I think it should be opcode 0028 ($int > int, not $float > float). Also, is the $fwset gosub needed? As far as I can tell it just sets a var from the array to the car handle it already is. Next, wouldn't this move the cars around in a circle place-by-place, as in they will jump 360/$fwcars degrees each time? Where as it would be better if they moved 1 degree at a time, then a wait sets the time between each degree like:

 

 

:ferriscalculations //gosub0093: 6@ = int_to_float $fwloop0017: 6@ /= 100089: 4@ = $fwcarang006B: 4@ *= 6@005B: 4@ += 5@00D6: if 08031:    NOT 4@ >= 360.0004D: jump_if_false ££labelferrisleave000F: 4@ -= 360.0:labelferrisleave0051: return //end gosub//code starts here:labelferris1100093: 0@ = int_to_float $fwcars0005: $fwcarang = 360.00077: $fwcarang /= 0@:labelferriscomplete0089: 5@ = $fwzangle:labelferris1200001: wait $fwwait0084: $fwloop = $fwcars0010: $fwloop *= 100453: set_object $fwwheel angle $fwxangle $fwyangle $fwzangle0453: set_object $fwcenter angle $fwxangle $fwyangle $fwzangle:labelferris1250004: $fwget = ��labelferris1010008: $fwget += $fwloop0050: gosub $fwget0050: gosub ££ferriscalculations0453: set_object $fwcenter angle $fwxangle $fwyangle 4@0400: 0@ 1@ 2@ get_point_on_object_plane $fwcenter $fwradius 0.0 0.0// Not sure about the parameter order, I'm using the DB here and it's different to MB which I'm coding in if you hadn't noticed.01BC: put_object $fwcar at 0@ 1@ 2@000C: $fwloop -= 1000D6: if 08028:   NOT $fwloop > 0004D: jump_if_false ££labelferris1250009: 5@ += 1.0 //When finished looping through each car move to the next degree and jump to where there is a wait00D6: if 00037:   5@ >= $fwzangle //if it got too big reset to original starting position (as it has come full circle)004D: jump_if_false ££labelferriscomplete0002: jump ££labelferris120

 

This can probably be optimised somewhere.

Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3374276
Share on other sites

I think you misunderstood the code (or I wrote it wrong, that was whipped up in minutes when I made the post so could easily be wrong). What it's MEANT to do it, each time the thread loops (i.e. every time it reaches the first wait). The MAIN WHEEL turns however many small degrees you set it to. Then the hidden centre object turns that little bit and 360/$fwcars $fwcar times (i.e. it does a full circle in bits and ends up pointing in the same direction as the main wheel (though due to rounding errors and other limitations this position is then set to EXACTLY the wheels rotation so the cars don't slowly get out of synch)). Every time the hidden centre reaches a point round it's full circle, it calculates an offset from there and places the next car in the array there. No, $fwget isn't needed, I was just modifying code for PatricW's Marina Car Park Mod from memory as it was similar.

 

But yes, the overall effect is that the wheel turns little bits (it was one of the user definable variables at the top IIRC) while the centre spins round in larger bits to calculate the new positions of the cars round the edge, spaced at your 360/$fwcars.

Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3374428
Share on other sites

Ah I didn't did I, I'm glad one of us is awake. Cheers.

 

 

:labelferris1000005: $fwxangle = 45.0 // Initial angle of the ferris wheel0005: $fwyangle = 0.0 // Initial TILT of the wheel, alter it if you REALLY want0005: $fwzangle = 90.0 // Initial direction of the ferris wheel0005: $fwradius = 30.0 // Radius of ferris wheel, set to yours0004: $fwwait = 10 // Delay in ms0005: $fwspeed = 5.0 // Angle to increment by each step0005: $fwcars = 8 // Change to add more cars, they will be placed automatically but you will need to add them to the list, I couldn't be bothered to use my own arrays (they're so hard to implement even I can't be arsed!)0002: jump ££labelferris110// List of cars part one (add your extras to both):labelferris1010084: $fwcar = $fwcar00051: return0084: $fwcar = $fwcar10051: return0084: $fwcar = $fwcar20051: return0084: $fwcar = $fwcar30051: return0084: $fwcar = $fwcar40051: return0084: $fwcar = $fwcar50051: return0084: $fwcar = $fwcar60051: return0084: $fwcar = $fwcar70051: return// Part 2:labelferris1020084: $fwcar0 = $fwcar0051: return0084: $fwcar1 = $fwcar0051: return0084: $fwcar2 = $fwcar0051: return0084: $fwcar3 = $fwcar0051: return0084: $fwcar4 = $fwcar0051: return0084: $fwcar5 = $fwcar0051: return0084: $fwcar6 = $fwcar0051: return0084: $fwcar7 = $fwcar0051: return// You don't need to change owt below here.:labelferris1100093: 0@ = int_to_float $fwcars0005: $fwcarang = 360.00077: $fwcarang /= 0@:labelferris1200001: wait $fwwait0084: $fwloop = $fwcars0010: $fwloop *= 100453: set_object $fwwheel angle $fwxangle $fwyangle $fwzangle0453: set_object $fwcenter angle $fwxangle $fwyangle $fwzangle0089: 4@ = $fwzangle:labelferris1250004: $fwget = ££labelferris1010004: $fwset = ££labelferris1020008: $fwget += $fwloop0008: $fwset += $fwloop0050: gosub $fwget0400: 0@ 1@ 2@ get_point_on_object_plane $fwcenter $fwradius 0.0 0.0// Not sure about the parameter order, I'm using the DB here and it's different to MB which I'm coding in if you hadn't noticed.01BC: put_object $fwcar at 0@ 1@ 2@0051: gosub $fwset005D: 4@ += $fwcarang0453: set_object $fwcenter angle $fwxangle $fwyangle 4@000C: $fwloop -= 1000D6: if 00018:   $fwloop > 0004D: jump_if_false ££labelferris1300002: jump ££labelferris125:labelferris1300059: $fwzangle += $fwspeed00D6: if 00030:   $fwzangle > 360.0004D: jump_if_false ££labelferris120000D: $fwzangle -= 360.00002: jump ££labelferris120

 

 

Right, no wonder you couldn't understand it, my bad, sorry. This is the updated code, I added the angle update and fixed one opcode where for some reason I was using gtegf instead of gtgi, which is a bit of a random mix up.

Edited by Y_Less
Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3378804
Share on other sites

  • 4 weeks later...
chickenplucker

I always wanted a ferris wheel, so I thought I'd try your cool looking code out Y_less. But since I'm just a dumb map modder I need some help.

When I try to compile it in BW's mission builder at

 

000D: $fwzangle -=360.0

(second from bottom)

 

it says paramiter 2 not set.

I honestly did try to search around to see if I could solve this on my own before bumping.

 

Heres a pic of my Wheel (very crappy jpg)

Just to make sure, the cars are placed with the script right?

If you would some models of diffrent rides to experiment with just pm me and I'll see what I can do.

Edited by chickenplucker
Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3439185
Share on other sites

  • 5 months later...

Huge bump but meh. I was working on a little project the other day and I found a bug in the set_object_rotation OpCode (yes, the OpCode, not my code). X and Z rotatation are calculated around the world X and Z axies, Y rotation is done around the models Y axis (don't know how I missed this before).

 

An example of the problems this can cause is if you set an object to an initial rotation of:

 

90.0 0.0 0.0

 

the object will be facing the ground and rotating the model around either the Y or Z axies will look exactly the same.

Link to comment
https://gtaforums.com/topic/225375-rotating-objects-2/#findComment-3749857
Share on other sites

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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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