HadesOfGTA Posted June 28, 2013 Share Posted June 28, 2013 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! Link to comment Share on other sites More sharing options...
nixolas1 Posted June 29, 2013 Share Posted June 29, 2013 (edited) 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 June 29, 2013 by nixolas1 Link to comment Share on other sites More sharing options...
HadesOfGTA Posted July 1, 2013 Author Share Posted July 1, 2013 Sweet! Thank you for the response nixolas1 I am now able to rotate in-game Link to comment Share on other sites More sharing options...
HadesOfGTA Posted July 2, 2013 Author Share Posted July 2, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now