Jump to content

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


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! :)

Link to comment
https://gtaforums.com/topic/772862-sacmathmoving-my-coronas-away-from-my-actor/
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

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}

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!

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! :)

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

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

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        4@ = 0.5        00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@        for 30@ = 0 to 20            wait 0            // first corona            0087: 11@ = 1@ // submit base coords to another var for calculation                                                                 0087: 12@ = 2@ // submit base coords to another var for calculation                                                                 0087: 13@ = 3@ // submit base coords to another var for calculation                                                                02F6: 5@ = sine 45.0 // get sine from 45 degree                                                           02F7: 6@ = cosine 45.0 // get cosine from 45 degree                                                         02F7: 7@ = cosine 30.0 // get cosine from 30 degree for vertcal orientation                                                        006B: 5@ *= 4@  // multiplicate the sine result with a Multiplicator to give the expension                                                  006B: 6@ *= 4@  // multiplicate the cosine result with a Multiplicator to give the expension                                                  006B: 7@ *= 4@  //multiplicate the cosine result with a Multiplicator to give the expension                                                  005B: 11@ += 5@  // add the result to the var with the base coords  as X result                                               005B: 12@ += 6@  // add the result to the var with the base coords  as Y result                                               005B: 13@ += 7@  // add the result to the var with the base coords  as Z result                                               04D5: create_corona_at 11@ 12@ 13@ radius 0.5 type 3 flare 0 RGB 150  0  255             4@ += 0.05// inrease multiplicator to inrease the expansion for next corona (loop)                                                                                                                                            // second corona                                                                                                                                                                                                0087: 11@ = 1@ // (float)                                                                 0087: 12@ = 2@ // (float)                                                                 0087: 13@ = 3@ // (float)                                                                 02F6: 5@ = sine 130.0 // (float)                                                          02F7: 6@ = cosine 130.0 // (float)                                                        02F7: 7@ = cosine 45.0 // (float)                                                         006B: 5@ *= 4@  // (float)                                                  006B: 6@ *= 4@  // (float)                                                  006B: 7@ *= 4@  // (float)                                                  005B: 11@ += 5@  // (float)                                                 005B: 12@ += 6@  // (float)                                                 005B: 13@ += 7@  // (float)                                                 04D5: create_corona_at 11@ 12@ 13@ radius 0.5 type 3 flare 0 RGB 0  255  55             4@ += 0.05                                                                                                                                            // third corona                                                                                                                                                                                                                                                                             0087: 11@ = 1@ // (float)                                                                 0087: 12@ = 2@ // (float)                                                                 0087: 13@ = 3@ // (float)                                                                 02F6: 5@ = sine 230.0 // (float)                                                          02F7: 6@ = cosine 230.0 // (float)                                                        02F7: 7@ = cosine 5.0 // (float)                                                          006B: 5@ *= 4@  // (float)                                                  006B: 6@ *= 4@  // (float)                                                  006B: 7@ *= 4@  // (float)                                                  005B: 11@ += 5@  // (float)                                                 005B: 12@ += 6@  // (float)                                                 005B: 13@ += 7@  // (float)                                                 04D5: create_corona_at 11@ 12@ 13@ radius 0.5 type 3 flare 0 RGB 255  0  25             4@ += 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 

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!

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! :)

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.