Deal Damage On How Past A Part Is Moving

  1. What do you want to achieve? Keep it simple and clear!
    Deal Damage On How Fast A Part Is Moving

  2. What is the issue? Include screenshots / videos if possible!
    No method i tried worked

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Dev fourms and videos online

Code:

Head.Touched:Connect(function(hit)
	if hit.Parent and hit then
		if hit.Parent:FindFirstChild("Humanoid") and playerHumanoid.Health ~= 0 and hit.Parent.Name ~= script.Parent.Name then
			local humanoid = hit.Parent:FindFirstChild("Humanoid")

			if hurtDebounce == false then
				hurtDebounce = true
				local hurtValue = 15
				hit.Parent.Humanoid.Health -= hurtValue
				warn("hurt humanoid for " ..hurtValue)
				task.wait(0.5)
				hurtDebounce = false
			end
		end
	end
end)

What do you mean by “how past”?

Fast* Mistype MB, Fixing now (words and stuff)

First of all, the methods you are using are extremely inefficient and bad. I recommend using raycasts for the bullet to see if it collides with an object and then deal damage accordingly.

When talking projectile hit-detection, you’ll want to use rays over BasePart.Touched. This is because BasePart.Touched can only fire when two objects are determined to be colliding, and this check can only be made at a certain rate. Projectiles often travel at high speeds, which means they can travel a great distance between frames, and though the projectile might be on a collision course with something, it may end up on the other side of that object on the next frame, where the physics engine will notice the collision. Cast a ray from the projectile’s previous position to its current position. Do this every RunService.PostSimulation. Utilize PostSimulation’s “deltaTime” parameter to calculate the speed at which the projectile is travelling via Velocity = Distance / Time. If your damage linearly increases with the speed of the projectile, you can set up Damage = IncreasePer * UnitOfSpeed + Default, where UnitOfSpeed = Velocity. You may recognize this as y = mx + b

1 Like

You can indeed use raycasts here. But to get an actual projectile (and not just hitscan, you’ll have to use fastcast). and for that you’ll need to make some additions to .lengthchanged given your projectile is one that changes speed throughout

  1. actual projectile acceleration, so the bullet speed increases with each length changed given DT
  2. if the projectile is like a cannonball, to include a spherecast that uses the fastcast bullets current position.

However, you can also use raycasthitbox v4 with physics. Make a projectile instance, set up raycasthitbox v4 attachments, and move it using whatever physics you want to use.
To calculate the speed using physics, it’s Object.Velocity.Magnitude. To get a damage multiplier value clamp it like this.

local Damage = 25

local CurrentSpeed = Projectile.Velocity.Magnitude
local MaxSpeed = 100 -- max speed of the projectile
local DamageMulti = (CurrentSpeed/MaxSpeed)
Damage *= DamageMulti

DamageMulti should be CurrentSpeed/MaxSpeed as the damage would be higher with a faster bullet, and none with a stopped bullet

1 Like

Thought I edited it to have that, weird

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.