Quantcast
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. Los Santos Tuners
      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. GTA San Andreas

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

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

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    1. Grand Theft Auto Series

      1. 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. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    6. 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

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

Resurrecting a vehicle in-motion


whorse
 Share

Recommended Posts

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 by whorse
Link to comment
Share on other sites

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 by Jitnaught
Link to comment
Share on other sites

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 by whorse
Link to comment
Share on other sites

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 by InfamousSabre
Link to comment
Share on other sites

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

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;
Link to comment
Share on other sites

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

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

  • 1 year later...
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

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.