You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I currently am trying to make a simple weapon system using fastcast to render bullets quickly on the client. How do I account for player movement when I spawn bullets to shoot? -
What is the issue? Include screenshots / videos if possible!
Whenever the player moves, the bullet spawns at an offset position to the gun point. As I’ve noticed, the offset amount scales the greater the player’s walkspeed is. The issue itself is mostly self-explanatory. Attached is a video as proof:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked through dev hub, however none of the solutions I’ve tried so far have actually worked.
Right now, what happens in my script is that a hitscan module passes in an origin, cast behavior, hit position, and shoot range into a module for creating cosmetic bullets. Then the cosmetic bullet is fired on a client caster. The origin for the hitscan module is determined using an attachment’s world position, which is on the viewmodel’s weapon.
Here’s the code
Hitscan Module:
local origin = self.pModule.camState == "FirstPerson" and self.v_weapon.Shoot.Attachment.WorldPosition
DrawCosmeticBullet(player, self.Shoot.BULLET_NAME, self.castBehavior, origin, mouse.Hit.Position, self.Shoot.BULLET_RANGE)
DrawCosmeticBullet:
return function(Sender : Player,
BulletTemplateName : string,
CastBehavior : FastCast.FastCastBehavior,
Origin : Vector3,
MouseHit : Vector3,
Range : number,
ShootPointInfo)
local Direction = (MouseHit - Origin).Unit
ClientCaster:Fire(Origin, Direction, 100, CastBehavior)
end
The issue is likely not related to a delay on the scripting side. I used os.clock() to check the time in between when the shoot request is made, and the fastcast bullet fires, and it’s a negligible amount.
Because I noticed the offset had a correlation to the player’s velocity, I tried adding the velocity to the player’s movespeed but it was still offset by a small amount. I don’t know if I’m doing it wrong or something, but this is generally what I tried:
local StartPoint = Origin + RootPart.Velocity * deltaTime
I seriously don’t know what the issue is at this point, if anyone could offer any advice or help I’d greatly appreciate it!