Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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

Move Objects After Spawn (C++)


HadesOfGTA
 Share

Recommended Posts

Right now I am playing with objects, more precisely, trying to figure out how to rotate and move objects AFTER they have been spawned. Right now I am playing with an attached object to my face because it's easier to see and I don't have to go somewhere to test movement. Here is what I am doing at the moment (with no luck, and not even sure if I am on the right path):

 

 

 	if(IsBitSet(GetKeyState(VK_CONTROL), 15)) {   eModel pigeon = MODEL_CJ_PIGEON_06;   Object newObj;   f32 zForce = 0.0f;   f32 yForce = 0.0f;   f32 xForce = 0.0f;   AttachObjectToPed(newObj = CreateObjectTemp(pigeon),GetPlayerPed(), BONE_HEAD, 0, 0, 0, 0, 0, 0, false);      while(true){   	if(IsBitSet(GetKeyState(VK_CONTROL), 15)) {     xForce += 0.1f;     SetObjectRotation(newObj, xForce, yForce, zForce);   	}else if(IsBitSet(GetKeyState(VK_SHIFT), 15)) {     yForce += 0.1f;     SetObjectRotation(newObj, xForce, yForce, zForce);   	}else if(IsBitSet(GetKeyState(VK_MENU), 15)) {     zForce += 0.1f;     SetObjectRotation(newObj, xForce, yForce, zForce);   	}   	Wait(100);   } 	}

 

 

I am not even sure if I am on the right track, so any help would be greatly appreciated. Thank you! biggrin.gif

Link to comment
Share on other sites

Heh, well, it has to do with the way the game works. You cant set the normal ObjectRotation after you have attached it to a ped ( or anything else).

 

You will have to set the attach rotation to rotate it. AttachObjectToPed(newObj,GetPlayerPed(), BONE_HEAD, 0, 0, 0, rz, ry, rz, false);

change rx,ry,rz to change rotations. the value is given in radians.

 

For normal rotation the object must be unattached. then you can use SetObjectRotation, or (maybe) rotateObject.

 

To get some nice coordinates use GetOffsetFromCharInWorldCoordinates(ped, 0, 2,0, &x,&y,&z); which is 2m in front of ped.

 

And a simpler/more effective key event check is if (GetKeyState( VK_MULTIPLY ) < 0){

 

EDIT: rotateObject should in theory add rotation to the object from its current rotation values, while setObjectRotation resets the rotation to 0+yourValue.

Edited by nixolas1
Link to comment
Share on other sites

HadesOfGTA

Sweet! Thank you for the response nixolas1 biggrin.gif

 

I am now able to rotate in-game biggrin.gif

Link to comment
Share on other sites

HadesOfGTA

Nixolas1, Thank you again for your help in helping me to determine how to do this. I would like to post my code that I have developed just in case others come across this issue.

 

What this code does: Rotates and Moves an ATTACHED-TO-PLAYER object. Attach the object to the player, then pass the object and the ePedBone to the function. Please also note this function is best used offline as I didn't write in any checks when exiting this function in-game (i.e. deleting the object). Please also note, you will have to replace the hotkeys with functions that work for you. Simply use nixolas1's suggestion of GetKeyState(VK_KEY) < 0 accordingly.

 

 

void CustomFiberThread::AttachedObjectRotationAndMovementTest(Scripting::Object yourObject, Scripting::ePedBone myBone){/*****************************************************************CONTROLS:NUMPAD*    	Change Rotation/Movement modesARROW LEFT    Increase x/xrotCTRL + ARROW LEFT  Decrease x/xrotARROW DOWN    Increase y/yrotCTRL + ARROW DOWN  Decrease y/yrotARROW RIGHT    Increase z/zrotCTRL + ARROW RIGHT  Decrease z/zrotNUMPAD+    	Display current coordinates (x,y,z)NUMPAD-    	Display current rotation (pitch,yaw,roll)*****************************************************************/f32 x=0.0f,y=0.0f,z=0.0f,xrot=0.0f,yrot=0.0f,zrot=0.0f;bool rotMode = false;PrintStringWithLiteralStringNow("STRING", "Starting in Movement Mode", 1000, true);while(true) { Wait(100); if(IsBitSet(GetKeyState(HH_LEFT), 15)) { 	while(IsObjectAttached(yourObject)) {   DetachObject(yourObject, true); 	} 	 	if(IsBitSet(GetKeyState(HH_CONTROL), 15))   if(!rotMode)   	x-=0.05f;   else   	xrot-=0.05f; 	else   if(!rotMode)   	x+=0.05f;   else   	xrot+=0.05f; 	AttachObjectToPed(yourObject, GetPlayerPed(), myBone, x, y, z, xrot, yrot, zrot, false); } else if(IsBitSet(GetKeyState(HH_DOWN), 15)) { 	while(IsObjectAttached(yourObject)) {   DetachObject(yourObject, true); 	} 	 	if(IsBitSet(GetKeyState(HH_CONTROL), 15))   if(!rotMode)   	y-=0.05f;   else   	yrot-=0.05f; 	else   if(!rotMode)   	y+=0.05f;   else   	yrot+=0.05f; 	AttachObjectToPed(yourObject, GetPlayerPed(), myBone, x, y, z, xrot, yrot, zrot, false); } else if(IsBitSet(GetKeyState(HH_RIGHT), 15)) { 	while(IsObjectAttached(yourObject)) {   DetachObject(yourObject, true); 	} 	 	if(IsBitSet(GetKeyState(HH_CONTROL), 15))   if(!rotMode)   	z-=0.05f;   else   	zrot-=0.05f; 	else   if(!rotMode)   	z+=0.05f;   else   	zrot+=0.05f; 	AttachObjectToPed(yourObject, GetPlayerPed(), myBone, x, y, z, xrot, yrot, zrot, false); } else if(IsBitSet(GetKeyState(HH_ADD), 15)) { 	char RotMessage[300]; 	sprintf_s(RotMessage, 300, "x: %f y: %f z: %f", x, y, z); 	PrintStringWithLiteralStringNow("STRING", RotMessage, 1000, true); }else if(IsBitSet(GetKeyState(HH_SUBTRACT), 15)) { 	char RotMessage[300]; 	sprintf_s(RotMessage, 300, "xrot: %f yrot: %f zrot: %f", xrot, yrot, zrot); 	PrintStringWithLiteralStringNow("STRING", RotMessage, 1000, true); }else if(IsBitSet(GetKeyState(HH_MULTIPLY), 15)) { 	rotMode = !rotMode; 	PrintStringWithLiteralStringNow("STRING", (rotMode==false ? "Movement Mode" : "Rotation Mode"), 1000, true); }else if(IsBitSet(GetKeyState(HH_DIVIDE), 15)) { 	PrintStringWithLiteralStringNow("STRING", "Exiting rotation mode", 1000, true); 	DeleteObject(&yourObject); }}}

 

 

If you find that when you display the coordinates that the time displayed isn't long enough for you, simply increase the 1000 to a number that suites you. Time is in milliseconds. 1second = 1000 milliseconds. 5 seconds = 5000 milliseconds.

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.