Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

SA|C++|Math|Moving my corona's away from my actor


ceedj
 Share

Recommended Posts

Hi gang, as I continue shooting the last few episodes, I realize I'm getting closer to the end with no solution for my corona problem. Basically, I need my corona's to move away from my actor. Here's a snippet of code from my hook:

pGame->LoadModel(3090);		SCRIPT_WAIT(0);	if (ClaudeOn == 1 && ClaudeOn1 == 1 && ClaudeOn2 == 1)	{pClaude1->GetActorCoordOffset(0.0f, 0.0f, 0.5f, &fFO1X, &fFO1Y, &fFO1Z);	pFObj1 = new ScriptObject();	pFObj1->IntObject(3090, fFO1X, fFO1Y, fFO1Z);	CallOpcode(&object_visible, pFObj1->GetObj(), 0);	fFO1Z2 = fFO1Z + 30.0f;	pClaude2->GetActorCoordOffset(0.0f, 0.0f, 0.5f, &fFO2X, &fFO2Y, &fFO2Z);	pFObj2 = new ScriptObject();	pFObj2->IntObject(3090, fFO2X, fFO2Y, fFO2Z);	CallOpcode(&object_visible, pFObj2->GetObj(), 0);	fFO2Z2 = fFO2Z + 30.0f;(etc)

And here is the traveling part:

CoLoop2:	SCRIPT_WAIT(0);	CallOpcode(&move_object_xyz, pFObj1->GetObj(), fFO1X, fFO1Y, fFO1Z2, 0.0f, 0.0f, 0.052f, 0);	CallOpcode(&get_object_pos, pFObj1->GetObj(), &fFO1X, &fFO1Y, &fFO1Z);	CallOpcode(&add_corona, fFO1X, fFO1Y, fFO1Z, 0.5f, 1, 0, 200, 0, 0);	elapsed_time =::GetTickCount() - Start_point;	if (elapsed_time > 2000)	{CallOpcode(&move_object_xyz, pFObj2->GetObj(), fFO2X, fFO2Y, fFO2Z2, 0.0f, 0.0f, 0.052f, 0);	CallOpcode(&get_object_pos, pFObj2->GetObj(), &fFO2X, &fFO2Y, &fFO2Z);	CallOpcode(&add_corona, fFO2X, fFO2Y, fFO2Z, 0.5f, 1, 0, 0, 200, 0);}	elapsed_time =::GetTickCount() - Start_point;	if (elapsed_time > 4000)	{CallOpcode(&move_object_xyz, pFObj3->GetObj(), fFO3X, fFO3Y, fFO3Z2, 0.0f, 0.0f, 0.052f, 0);	CallOpcode(&get_object_pos, pFObj3->GetObj(), &fFO3X, &fFO3Y, &fFO3Z);	CallOpcode(&add_corona, fFO3X, fFO3Y, fFO3Z, 0.5f, 1, 0, 0, 0, 250);}	elapsed_time =::GetTickCount() - Start_point;	if (elapsed_time > 5000)(etc)

Essentially, I create an invisible object based on the Claude position, and attach a corona to it. The object moves slowly up the Z axis until it reaches 30.0, then stops. This is all in it's own thread, so it can loop around until all 44 objects/coronas reach the same height. What I would like to do (for dramatic purposes) is have them shoot away from my actor in the air, but I can't figure out how to get a direction for them to go in (the actor in the air is spinning in a looped animation until I tell it not to).

 

I'd like them to all go in different directions, away from the spinning actor. So, any ideas? Be happy to provide more detail if needed.

 

Thanks a bunch! :)

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

Assuming that you can get player position for start coords
then take any z_angle to give a direction and calculate coords from angle by using sine and cosine function

get_player_position_to <x>, <y>, <z>start_corona at <x>, <y>, <z>//--- take any z_angle to give a direction, 45 degree as example<Angle> = 45.0//--- and calculate coords from angle02F6: <cos> = cosine <Angle>02F7: <sin> = sinus <Angle>//--- use a multiplicator to increase or define the range<Mult> = 5.0//then the target will be ca. 5.0 units far from start coords<X-result> = <cos> * <Mult><Y-result> = <sin> * <Mult>//---  add the result to the start coords<Destination-X> = <x> + <X-result><Destination-Y> = <y> + <Y-result>

let your objects fly to different angle

and if you call opcode 0381, then you can use the result directly as input

0381: throw_object pFObj1 velocity_in_direction <X-result> <Y-result> 15.5
Link to comment
Share on other sites

Calculate the offset between player and a object, then add the result back to object. Do I get your point?

struct Coord{	float x, y, z;	void operator+=(const Coord &Right)	{		x += Right.x;		y += Right.y;		z += Right.y;	}	Coord operator-(const Coord &Right)	{		return{ x - Right.x, y - Right.y, z - Right.z };	}	Coord operator*(float mul)	{		return{ x * mul, y * mul, z * mul };	}};void xxx(){	Coord player, object, diff;	diff = object - player;	object += diff * 1.0f; //custom multiplier}
Link to comment
Share on other sites

You know, I watched Season 1 of PEDS the other night, just for fun. I remember how easy it was to set up a couple of actors and let them talk.

 

Ahh, the good old days. :D

 

Sort of works, needs some tweaking (I need to get in and out of both threads), so I'll leave it unsolved until I sort it out and post my final code.

 

Thanks very much guys!

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

Ok, slight problem, I can't attach a corona to a moving object (with 0381); in fact, I may not be able to get coords of an object in motion, which is how I "attach" the corona. It works with 034E (slide object xyz), but has the annoying aspect of moving along the x axis first, then the y axis. So, anyone have any further ideas of how to get an object to move along x and y at the same time, without using 0381? Invisible car comes to mind, but that's a lot of adding roads, etc midair.

 

If not, I can work with using 034E, just wont look as smooth as I'd like. Thanks again! :)

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

Why would you be unable to? I think, people have already shown the answer. COS (02F7) and SIN (02F6) compute the direction along the X and Y axes given an angle, which dictates the quadrant of the cartesian coordinate system the direction will point towards. The resulting coordinates would represent an unit vector (normalized), a particular segment of an unit circle (with radius one and centre [0, 0]). Assuming you would like to use SET_OBJECT_VELOCITY (0381), the Z coordinate isn't prone to this treatment as it just indicates how quickly the force would move our object/s vertically, hence it can be equal to 1. Multiply the vector coordinates by a constant value to increase or decrease the motion speed and you are ready to throw your stuff.

Edited by Wesser

012          345
678   9A   BCD
EFG HIJK LMN
OPQR  STUV
WX    YZ

Link to comment
Share on other sites

I may have misspoke, when I said "unable to", I meant that my add corona codes don't appear to be getting the coordinates to pass along to my corona, which is in a loop. The math works fine, the object moves to where it should, but either due to a game limitation with 0381, or my implementation (btw, tried in and out of a loop, same results) a corona will not follow along using get_object_xyz and add_corona in a loop. This all works as advertised using 034E, but it's all herky-jerky. :D

Edited by ceedj

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

You don't need an object, try the cleo script below, it shows 3 coronas, spreading out of CJ's center

{$CLEO .cs}thread 'CORANA'while true    wait 0    if        0256:   player $PLAYER_CHAR defined    then        [email protected] = 0.5        00A0: store_actor $PLAYER_ACTOR position_to [email protected] [email protected] [email protected]        for [email protected] = 0 to 20            wait 0            // first corona            0087: [email protected] = [email protected] // submit base coords to another var for calculation                                                                 0087: [email protected] = [email protected] // submit base coords to another var for calculation                                                                 0087: [email protected] = [email protected] // submit base coords to another var for calculation                                                                02F6: [email protected] = sine 45.0 // get sine from 45 degree                                                           02F7: [email protected] = cosine 45.0 // get cosine from 45 degree                                                         02F7: [email protected] = cosine 30.0 // get cosine from 30 degree for vertcal orientation                                                        006B: [email protected] *= [email protected]  // multiplicate the sine result with a Multiplicator to give the expension                                                  006B: [email protected] *= [email protected]  // multiplicate the cosine result with a Multiplicator to give the expension                                                  006B: [email protected] *= [email protected]  //multiplicate the cosine result with a Multiplicator to give the expension                                                  005B: [email protected] += [email protected]  // add the result to the var with the base coords  as X result                                               005B: [email protected] += [email protected]  // add the result to the var with the base coords  as Y result                                               005B: [email protected] += [email protected]  // add the result to the var with the base coords  as Z result                                               04D5: create_corona_at [email protected] [email protected] [email protected] radius 0.5 type 3 flare 0 RGB 150  0  255             [email protected] += 0.05// inrease multiplicator to inrease the expansion for next corona (loop)                                                                                                                                            // second corona                                                                                                                                                                                                0087: [email protected] = [email protected] // (float)                                                                 0087: [email protected] = [email protected] // (float)                                                                 0087: [email protected] = [email protected] // (float)                                                                 02F6: [email protected] = sine 130.0 // (float)                                                          02F7: [email protected] = cosine 130.0 // (float)                                                        02F7: [email protected] = cosine 45.0 // (float)                                                         006B: [email protected] *= [email protected]  // (float)                                                  006B: [email protected] *= [email protected]  // (float)                                                  006B: [email protected] *= [email protected]  // (float)                                                  005B: [email protected] += [email protected]  // (float)                                                 005B: [email protected] += [email protected]  // (float)                                                 005B: [email protected] += [email protected]  // (float)                                                 04D5: create_corona_at [email protected] [email protected] [email protected] radius 0.5 type 3 flare 0 RGB 0  255  55             [email protected] += 0.05                                                                                                                                            // third corona                                                                                                                                                                                                                                                                             0087: [email protected] = [email protected] // (float)                                                                 0087: [email protected] = [email protected] // (float)                                                                 0087: [email protected] = [email protected] // (float)                                                                 02F6: [email protected] = sine 230.0 // (float)                                                          02F7: [email protected] = cosine 230.0 // (float)                                                        02F7: [email protected] = cosine 5.0 // (float)                                                          006B: [email protected] *= [email protected]  // (float)                                                  006B: [email protected] *= [email protected]  // (float)                                                  006B: [email protected] *= [email protected]  // (float)                                                  005B: [email protected] += [email protected]  // (float)                                                 005B: [email protected] += [email protected]  // (float)                                                 005B: [email protected] += [email protected]  // (float)                                                 04D5: create_corona_at [email protected] [email protected] [email protected] radius 0.5 type 3 flare 0 RGB 255  0  25             [email protected] += 0.02                                                                            end    endend

the method

<counter> = 0            <Mult> = 0.5//define a multiplicator            get_player_position_to <x1>, <y2>, <z3>repeat   //submit base coords to another var for calculation, because it needs to keep the start coords                         <X11> = <x1>                                                                                                           <Y12> = <y2>                                                                                                           <Z13> = <z3>                                                                                                                                                                                                                                  //--- take any z_angle to give a direction, 45 degree as example                                                       45.0 for X/Y and 30.0 for Z                                                                                                                                                                                                                   //--- and calculate coords from angle                                                                                  02F6: <sin_x> = sinus 45.0                                                                                             02F7: <cos_y> = cosine 45.0                                                                                            02F7: <cos_z> = cosine 30.0                                                                                                                                                                                                                   //--- multiplicate sine/cosine result with a Multiplicator to give the expension                                       <X-result> = <sin_x> * <Mult>                                                                                          <Y-result> = <cos_y> * <Mult>                                                                                          <Z-result> = <cos_z> * <Mult>                                                                                                                                                                                                                 //---  add the result to the start coords                                                                              <Destination-X> = <X11> + <X-result>                                                                                   <Destination-Y> = <Y12> + <Y-result>                                                                                   <Destination-Z> = <Z13> + <Z-result>                                                                                                                                                                                                          04D5: create_corona_at <Destination-X> <Destination-Y> <Destination-Z> radius 0.5 type 3 flare 0 RGB 150  0  255                                                                                                                              // inrease multiplicator to inrease the expansion for next corona loop                                                 <Mult> + 0.1                                                                                                                                                                                                                                  <counter> + 1                                                                                                       until  <counter> > 20 
Link to comment
Share on other sites

Interesting. Works via CLEO; there must be some memory addy in my hook that is preventing 04D5 from showing more than two coronas.

 

I love this approach, like the idea of the counter. Will play around with this some more, THANK YOU, ZAZ you rock!

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

Ok! Got it working; though I still can't do more than one corona with 04D5, I'm thinking this is more to do with the hook interfering somehow than anything else, as ZAZ's code above works fine in a CLEO environment. Right, on with the code:

SCRIPT_WAIT(0);	CorOff1 = 1; //Switch to turn off corona from the rise code	CallOpcode(&get_object_pos, pFObj1->GetObj(), &fFO1X, &fFO1Y, &fFO1Z);//Get obj coords it was attached to	pClaude1->GetActorZ(&fTempZangle);//angle of dead Claude	fMult = 0.5f;//Multiplier, controls how far corona travels	for (int Cor = 0; Cor < 75; ++Cor)//For loop to make it all travel	{SCRIPT_WAIT(0);//Needed to make for loop work	fX = fFO1X;//Obj X	fY = fFO1Y;//Obj Y	fZ = fFO1Z;//Obj Z	CallOpcode(&cosine, fTempZangle, &fSin);//Switched due to old ini definition	CallOpcode(&sine, fTempZangle, &fCos);//Switched due to old ini definition	fResX = fSin * fMult;	fResY = fCos * fMult;	fDesX = fResX + fX;	fDesY = fResY + fY;	CallOpcode(&create_corona_3d, fDesX, fDesY, fZ, 0.5f, 3, 0, 200, 0, 0);\\Create the corona	fMult += 0.8f;}//Controls speed of corona	elapsed_time2 =::GetTickCount() - Start_point2;//check time elapsed	if (elapsed_time2 > 5000)	{CorOff2 = 1;//Switch to turn off corona from the rise code, etc	CallOpcode(&get_object_pos, pFObj2->GetObj(), &fFO2X, &fFO2Y, &fFO2Z);	pClaude2->GetActorZ(&fTempZangle2);	fMult = 0.5f;	for (int Cor = 0; Cor < 75; ++Cor)

The Sine and Cosine opcodes are switched because I had an old sascm.ini that I was working from all those years ago. In order not to break anything I still need to use, I kept it, and switched it in the code above.

 

Looks really great, thanks for the help and insight! :)

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
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
 Share

  • 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.