Replicated CFrames are not correct

Hello, I am making a Top-Down shooter game currently and I am having this issue and that is the bullet CFrame replication to other clients

Here is an attached video of the issue:

(dont mind the character not taking damage, I forgot to check for accessories)

So as you can see when I shoot straight the bullet is replicated to the other client as like turned a different way and I am not quite sure why.

The method that I am currently using is:


image
image

(for now, I am just firing the clients with the exact same CFrame rather than doing raycast checks until i fix the issue)

I am wondering if CFrames can get altered when firing server, I am calling the exact same function to create the bullet as well. If anyone knows, your help is greatly appreciated!

2 Likes

Roblox serializes all data that’s passed thru remotes. The engine also works with 32 bit floats, while lua works with 64 bit double floats. These can result in small changes due to rounding.

It’s such a minute change that I don’t think it’s the problem here tho. The angle of error being constant makes it seems more likely that the math using the server supplied Vector is off.

You can probably drop this data from the remote event entirely. The bullets directly follow the gun’s direction, and the gun is rotated by the character rotating. You should be able to find Origin as shootingCharacter.Gun.Position and Vector as shootingCharacter.Gun.CFrame.LookVector

3 Likes

Ah, I could try this. And the vector variable was just me combining the 3 different vectors into one. I will let you know

Sorry to reply so late, I was just finishing up school work. I’ve tried this method and it is very close however it still is off by a bit I have no clue why, do you have any other suspicions as to why it could be happening? lmk if you need code

Does it fix it’s self and become accurate when you stop moving the character? If so then the problem is the physics replication latency.

for the most part yes, when my character is turned on certain angles it does do that but honestly a lot better than it was before. I think I might just add a bean shaped hitbox around my character once i import the custom characters

how do you think it looks?

edit:

I also need to add my own custom character movement for the character turning to work properly when walking

There is physics replication latency but it’s pretty minor on the local host test. This was one of the only frames that I could find a stark contrast between local client angle and other client viewing angle. This could become a significant problem in a production environment.

To fix this you may want to have the shooting client send it’s barrel LookVector in the event telling the server the gun was fired, then have viewing clients use that remote provided vector instead of having them use the current gun lookvector.

It’s looking pretty good, but you might want to use a new vector from the gun barrel to the mouse position instead of the barrel LookVector it’s self, unless you could animate the arm to adjust the angle there. If you do that you’re gonna want to remember to overwrite the Mouse.Hit.Position.Y value with the barrel’s current position.Y so the bullets stay level.

1 Like

oh shoot! I didnt even notice that, I’ll try sending that to server because it probably will work better and also with the offset, that is just from the character turning, I need to rewrite it and add some small calculation to fix it. For the Y axis positions you were saying, I have it set for the barrel position already but the walking animations mess everything up

Hey sorry for the late response and as I was writing this the power went out and crashed studio which is nice… but this is how it was before it went out

I tried out the method you provided and this is how it turned out:

nevermind, the video file got deleted and I need to rewrite it all

Hey, just wanted to let you know that I found a fix! I was reading around and found that serializing the CFrames through the remotes is what I needed, heres a video:

Thank you for all of your great suggestions!!

1 Like