I am making a repelling system in my game where you can repel a projectile, which doubles its speed every time(similar to the game bladeball). Unfortunately after it gains enough speed it gets more and more unlikely that the hit will actually register on the player. At the moment I have a while loop that raycasts in front of the projectiles current position and I am using linear velocity for its movement. The while loop is using task.wait which is as fast as the detection can get. I tried heartbeat but that is exactly the same speed as task.wait . Am I simply out of luck or is there a way around this?
You need to do anti-tunneling by doing a raycast between the position of the object during the last frame and the current frame.
Do I do a raycast in the front and behind in that case?
It’d look something like this:
local RunService = game:GetService("RunService")
local bullet = workspace.Bullet
local bulletConnection
local function bulletStep(dt: number)
local lastPosition = bullet.Position
bullet.CFrame *= CFrame.new(-Vector3.zAxis)
local result = -- do a raycast forward from last position to the current position
if result then
bulletConnection:Disconnect()
-- whatever you wanna do
end
end
bulletConnection = RunService.Heartbeat:Connect(bulletStep)
So I must not use LinearVelocity? I find it is more smooth than CFrame at high speeds, but I will change if necessary. I found changing the Network ownership of the projectile to nil made the velocity a lot smoother when near other players.
You don’t need to use CFrames, you can just store the last position outside of the loop. The reason LinearVelocity looks better is probably because you’re doing the bullets on the server
I am doing it on the server. I am not very experienced in projectiles. I just figured it would be better as I don’t want the player on the receiving end to look like they got hit from out of nowhere.
It’ll be laggier and more inconsistent on the server, but doing it on the client is a bit more complicated because you have to know how the networking and stuff works. If it’s your first time, doing it on the server is fine
Thanks for all the help, I will keep it on the server for now and put networking on my to learn list of things
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.