Author Topic: Workaround for inaccurate vectors on mounted player vehicles?  (Read 1874 times)

If I take a tank turret and mount it to a rowboat's passenger seat, and then I switch into the tank turret and fire, I notice that the projectile will be slightly bent down to the right. The effect is exaggerated the more south the boat is facing.

For example, consider the following boat, it is spawned facing north, and then two tank turrets are mounted, and the first tank turret is de-spawned, leaving just one tank turret in the forward passenger seat.



Upon firing this turret, you get this:



A (seemingly) perfectly accurate shot. However: Spin the boat around so it's facing south, and then taking a shot, will result in this:



A shot that bends off to the right, and down a little. Now, spin the boat back facing north, and you get this:



The turret is now shooting inaccurately in every direction. (This was tested with default add-ons only)

This causes a major inconvenience for me for my heavy machinegun add-on that I'm working on. Consider the following, I have set up my turret to spawn two pong projectiles at slot transforms mount1 and mount2. When the gun is mounted to the back of a physics vehicle, I get the following:



The lines are directly in the center, resulting in accurate shots. However, mount the gun to a player vehicle that's facing south, you get this:



The lines are curved off to the right, just like the projectiles. EyeVector of the player and the turret, muzzleVector of the player and the turret, and the vector subtracted from these slot transforms are all inaccurate when mounted to a player vehicle facing south.
 
Is there any way to detect and account for this? Have any of you even experienced this before? Any help would be appreciated.
« Last Edit: December 07, 2017, 06:10:33 PM by Rally »

It looks to me like the mounted PlayerVehicle is visually offset. The game thinks it's directly south, which is why the transform and the muzzleVector suggest it is facing directly south, but visually the player vehicle is rotated slightly out of whack

A very unscientific test:


These bullets are all traveling directly south. However, upon closer inspection it looks like the playervehicle is bent slightly left, which is why when mounted to it would make it so appear that the bullets are curving to the right:



EDIT:

It appears it happens when a playervehicle is spawned in general and not when something is mounted to it. Here's an example with the default rowboat. These rowboats were spawned facing south and north respectively. You can see the south facing both is much more offset to the one side whereas the north facing boat is only slightly offset to the one side.

getTransform() is reporting that both of these boats are facing directly south and north respectively, which is not entirely accurate.

« Last Edit: December 08, 2017, 05:59:48 AM by Rally »

yah ive had this issue before im pretty sure its because of some rotational data gets rounded off when they get compressed over the networking protocol

Oh god I'm having this exact issue with my laser turret on Hoth firing slightly to the right.

yah ive had this issue before im pretty sure its because of some rotational data gets rounded off when they get compressed over the networking protocol
Would this not occur in a singleplayer/LAN session?

It's a visual error thanks to the compression of exact angles for players when their transform is sent from the server. You can see it in action by going third person and switching between the driver and passenger seat in a rowboat at inexact angles.

Ok, quick rundown on why it happens:

1. Driver of bot has their control object set to it so their client performs prediction on it, so the angles they see are exact based on their input.
2. Change of angles are sent to the server, this is relatively unaffected by compression (it's a delta) so the server replicates the exact transform. Both the driver and the server know the "correct" transform of the boat.
3. Server needs to update everyone on what the boat looks like now. It will compress the boat's angles and everyone sees the boat slightly offset because of this. The driver does not get this update since they're predicting it anyways.
4. Driver switches seats. They aren't predicting the boat anymore since their control object is back to their player. The server sends the compressed angles to the ex-driver and he observes it "shifting," so now he sees what everyone else does.
5. Say the driver switches back without the boat changing... the old "correct" angles he had before the server crapped them up are still stored for prediction purposes, so he will see the boat snap back to the correct transform. This means only the server and the most recent driver or whatever changed the boats orientation know the correct angles, but even the driver won't see them if they aren't driving.
6. Anything that needs the transform of mounted objects will just use what the server knows. So when a tank turret is fired, a gun shot, etc. only the driver will have the correct visuals.

Annoying to fix since it's a client issue. I guess with every update the server gets, determine what the crapified transform would be, then for anything that needs to be visually correct feed it the vectors that come from that. That means emulating the angle rounding and re-calculating every mount... a clever way to get the info would be temporarily setting the transform, grabbing whatever, and restoring. Keep in mind this will force a position update so only do it when it's really needed.