whorse Posted October 24, 2016 Share Posted October 24, 2016 (edited) Hello, I have been trying to figure out a good way to fix a "dead" vehicle so that it is completely repaired. The normal SET_VEHICLE_FIXED() native makes a dead vehicle feel alive, but it has lost a lot of its physics, you cannot go first person in it and peds will not drive it. So I figured that - like with resurrecting peds - you probably have to duplicate and replace the vehicle with a new one to truly fix it. It's very easy for peds because you can just use PED::CLONE_PED(), but I have found no such native for vehicles so I have to copy everything manually. I have gotten it to the point where I can pretty seamlessly replace my midair-spinning dead vehicle with a new vehicle of the same type, color, mods and transfer the passengers, but the car's spinning/rotation angle will be inverted about half the time you press the 'repair' button . I'm not sure I really understand the math behind how to transfer rotational velocity from the old vehicle to the new one. Right now I get the old vehicle's quaternion, velocity and rotational velocity and transfer them all to the new vehicle, but I run into problems with the rotational velocity. I've tried a bunch of different combinations of parameters for APPLY_FORCE_TO_ENTITY() and this is what I have now: Vector3 velocity = ENTITY::GET_ENTITY_VELOCITY(oldVeh);Vector3 rotationalVelocity = ENTITY::GET_ENTITY_ROTATION_VELOCITY(oldVeh);Vector3 rotation = ENTITY::GET_ENTITY_ROTATION(oldVeh, 2);float x; float y; float z; float w;ENTITY::GET_ENTITY_QUATERNION(oldVeh, &x, &y, &z, &w);...ENTITY::SET_ENTITY_QUATERNION(newVeh, x, y, z, w);ENTITY::SET_ENTITY_VELOCITY(newVeh, velocity.x, velocity.y, velocity.z);if (!ENTITY::IS_ENTITY_UPSIDEDOWN(newVeh)) ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, rotationalVelocity.x, rotationalVelocity.y, rotationalVelocity.z, rotation.x, rotation.y, rotation.z, 2, true, false, true, false, false); else ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, -rotationalVelocity.x, -rotationalVelocity.y, -rotationalVelocity.z, rotation.x, rotation.y, rotation.z, 2, true, false, true, false, false); ...but it is still wrong a lot of the time when the car is spinning wildly in the air, and the new car will be spinning in a different way. How do you perfectly transfer rotational force from one object to another? Also the new vehicle is immune to being detected by my raycasting or manipulated by my gravity gun for a few seconds after it appears, even though I can apply the initial velocity instantly. If it collides with something, it becomes detectable. Why is this? Edited October 24, 2016 by whorse Link to comment Share on other sites More sharing options...
Jitnaught Posted October 24, 2016 Share Posted October 24, 2016 (edited) What I would try is something like Vector3 velocity = ENTITY::GET_ENTITY_VELOCITY(oldVeh);Vector3 rotationalVelocity = ENTITY::GET_ENTITY_ROTATION_VELOCITY(oldVeh);Vector3 rotation = ENTITY::GET_ENTITY_ROTATION(oldVeh, 2);float x; float y; float z; float w;ENTITY::GET_ENTITY_QUATERNION(oldVeh, &x, &y, &z, &w);//...ENTITY::SET_ENTITY_QUATERNION(newVeh, x, y, z, w);ENTITY::SET_ENTITY_ROTATION(newVeh, rotation.x, rotation.y, rotation.z, 2, true);ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, velocity.x, velocity.y, velocity.z, rotationalVelocity.x, rotationalVelocity.y, rotationalVelocity.z, 2, true, false, true, false, false); And to fix the raycast maybe you could use one of these natives (no idea if any of them will help) STREAMING::REQUEST_COLLISION_FOR_MODEL(Hash model)STREAMING::REQUEST_COLLISION_AT_COORD(float x, float y, float z)// while (!STREAMING::HAS_COLLISION_FOR_MODEL_LOADED(model)) STREAMING::REQUEST_COLLISION_FOR_MODEL(model);VEHICLE::SET_VEHICLE_DAMAGE(Vehicle vehicle, float xOffset, float yOffset, float zOffset, float damage, float radius, BOOL p6) Edited October 24, 2016 by Jitnaught Link to comment Share on other sites More sharing options...
unknown modder Posted October 24, 2016 Share Posted October 24, 2016 no point saving rotation and quaternion info, they both store the same info jedijosh920 1 Link to comment Share on other sites More sharing options...
whorse Posted October 24, 2016 Author Share Posted October 24, 2016 (edited) I had tried a couple collision related natives, but not those three or setting vehicle damage. I'll let you know if it works.and What I would try is something like Vector3 velocity = ENTITY::GET_ENTITY_VELOCITY(oldVeh);Vector3 rotationalVelocity = ENTITY::GET_ENTITY_ROTATION_VELOCITY(oldVeh);Vector3 rotation = ENTITY::GET_ENTITY_ROTATION(oldVeh, 2);float x; float y; float z; float w;ENTITY::GET_ENTITY_QUATERNION(oldVeh, &x, &y, &z, &w);//...ENTITY::SET_ENTITY_QUATERNION(newVeh, x, y, z, w);ENTITY::SET_ENTITY_ROTATION(newVeh, rotation.x, rotation.y, rotation.z, 2, true);ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, velocity.x, velocity.y, velocity.z, rotationalVelocity.x, rotationalVelocity.y, rotationalVelocity.z, 2, true, false, true, false, false);And to fix the raycast maybe you could use one of these natives (no idea if any of them will help)STREAMING::REQUEST_COLLISION_FOR_MODEL(Hash model)STREAMING::REQUEST_COLLISION_AT_COORD(float x, float y, float z)// while (!STREAMING::HAS_COLLISION_FOR_MODEL_LOADED(model)) STREAMING::REQUEST_COLLISION_FOR_MODEL(model);VEHICLE::SET_VEHICLE_DAMAGE(Vehicle vehicle, float xOffset, float yOffset, float zOffset, float damage, float radius, BOOL p6) I tried doing the APPLY_FORCE_TO_ENTITY like that first and it was very inconsistent. What seems to be especially hard to account for is the car's corkscrew motion (but not always?), while it is simultaneously spinning about another axis. I tried the upside-down check for a while and it seemed to make little difference, so I removed it.I'm not really that sure why, but I have had the most success with it by multiplying the rotation and rotational velocity by the vehicle's forward-vector, like this: ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, rotationalVelocity.x * fwdVector.x, rotationalVelocity.y * fwdVector.y, rotationalVelocity.z * fwdVector.z, rotation.x * fwdVector.x, rotation.y * fwdVector.y, rotation.z * fwdVector.z, 2, true, false, true, false, false); Here's a video clip of what I'm seeing (throwing my own vehicle around with a gravity gun and resurrecting it in midair):http://webm.land/media/EG36.webm Most of the replacements are pretty successful in that one (it's usually at most 50%), but you can see what I'm talking about at the end of the video. It's like the rotation of the new car is completely reversed of what the old car had, or something. no point saving rotation and quaternion info, they both store the same info Thanks for the heads up. I literally had never heard of a quaternion before seeing it in the natives.h, so I wasn't sure whether the x,y,z values were the same as for rotation. What is w, by the way? Edited October 24, 2016 by whorse Link to comment Share on other sites More sharing options...
InfamousSabre Posted October 25, 2016 Share Posted October 25, 2016 (edited) Instead of replacing the vehicle, maybe we should figure out how to fix the one we already have? It's likely just a flag set on the vehicle. I'll have some free time next week. If nobody has found it by then, I'll look into it. Have you tried applying the rotational velocity with isRel set to false? Edited October 25, 2016 by InfamousSabre Jitnaught 1 Link to comment Share on other sites More sharing options...
Jitnaught Posted October 25, 2016 Share Posted October 25, 2016 Instead of replacing the vehicle, maybe we should figure out how to fix the one we already have? It's likely just a flag set on the vehicle. I'll have some free time next week. If nobody has found it by then, I'll look into it. It has been looked into before, but was not completely figured out. Hopefully you can figure it out Link to comment Share on other sites More sharing options...
CamxxCore Posted October 31, 2016 Share Posted October 31, 2016 Hello, I have been trying to figure out a good way to fix a "dead" vehicle so that it is completely repaired. The normal SET_VEHICLE_FIXED() native makes a dead vehicle feel alive, but it has lost a lot of its physics, you cannot go first person in it and peds will not drive it. So I figured that - like with resurrecting peds - you probably have to duplicate and replace the vehicle with a new one to truly fix it. It's very easy for peds because you can just use PED::CLONE_PED(), but I have found no such native for vehicles so I have to copy everything manually. I have gotten it to the point where I can pretty seamlessly replace my midair-spinning dead vehicle with a new vehicle of the same type, color, mods and transfer the passengers, but the car's spinning/rotation angle will be inverted about half the time you press the 'repair' button . I'm not sure I really understand the math behind how to transfer rotational velocity from the old vehicle to the new one. Right now I get the old vehicle's quaternion, velocity and rotational velocity and transfer them all to the new vehicle, but I run into problems with the rotational velocity. I've tried a bunch of different combinations of parameters for APPLY_FORCE_TO_ENTITY() and this is what I have now: Vector3 velocity = ENTITY::GET_ENTITY_VELOCITY(oldVeh);Vector3 rotationalVelocity = ENTITY::GET_ENTITY_ROTATION_VELOCITY(oldVeh);Vector3 rotation = ENTITY::GET_ENTITY_ROTATION(oldVeh, 2);float x; float y; float z; float w;ENTITY::GET_ENTITY_QUATERNION(oldVeh, &x, &y, &z, &w);...ENTITY::SET_ENTITY_QUATERNION(newVeh, x, y, z, w);ENTITY::SET_ENTITY_VELOCITY(newVeh, velocity.x, velocity.y, velocity.z);if (!ENTITY::IS_ENTITY_UPSIDEDOWN(newVeh)) ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, rotationalVelocity.x, rotationalVelocity.y, rotationalVelocity.z, rotation.x, rotation.y, rotation.z, 2, true, false, true, false, false); else ENTITY::APPLY_FORCE_TO_ENTITY(newVeh, 5, -rotationalVelocity.x, -rotationalVelocity.y, -rotationalVelocity.z, rotation.x, rotation.y, rotation.z, 2, true, false, true, false, false); ...but it is still wrong a lot of the time when the car is spinning wildly in the air, and the new car will be spinning in a different way. How do you perfectly transfer rotational force from one object to another? Also the new vehicle is immune to being detected by my raycasting or manipulated by my gravity gun for a few seconds after it appears, even though I can apply the initial velocity instantly. If it collides with something, it becomes detectable. Why is this? I decided to look and figured it out. Infamous was right. It is a simple flag in the vehicle class: auto address = getScriptHandleBaseAddress(vehicle);*(BYTE*)(address + 0xD8) &= ~7; cp1dell, ikt, InfamousSabre and 3 others 6 Link to comment Share on other sites More sharing options...
whorse Posted November 1, 2016 Author Share Posted November 1, 2016 I decided to look and figured it out. Infamous was right. It is a simple flag in the vehicle class: auto address = getScriptHandleBaseAddress(vehicle);*(BYTE*)(address + 0xD8) &= ~7; Amazing! Thank you so much! I can just use this with SET_VEHICLE_FIXED and SET_VEHICLE_DEFORMATION_FIXED and the original vehicle is good as new Link to comment Share on other sites More sharing options...
stillhere Posted November 3, 2016 Share Posted November 3, 2016 Amazing! Thank you so much! I can just use this with SET_VEHICLE_FIXED and SET_VEHICLE_DEFORMATION_FIXED and the original vehicle is good as new If you still have the code for saving the vehicle mods and transferring the passengers, would you mind sharing that code? Link to comment Share on other sites More sharing options...
DankChaos Posted August 3, 2018 Share Posted August 3, 2018 On 11/1/2016 at 2:09 AM, whorse said: Amazing! Thank you so much! I can just use this with SET_VEHICLE_FIXED and SET_VEHICLE_DEFORMATION_FIXED and the original vehicle is good as new On 11/3/2016 at 2:33 AM, stillhere said: If you still have the code for saving the vehicle mods and transferring the passengers, would you mind sharing that code? You bitch, you wouldn't even give a naturally nice canadi-gander your yet so simple code? He joined in 2006. Do him a favor, give him the code. You whor-se ! -Sent from the library. -Tasked auto-send this message in exactly, 9 months from november, on the 3rd. at 12:13. 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