Why is the BodyVelocity/Touched event delayed?

What I’d like for the player to do is play an animation/effects once the hitbox has touched the wall. I’ve accomplished something identical to that, except for one minor issue which is showcased in the video below; I’d like for the player to not teleport back a few studs upon reaching the wall, but stay attached to the wall.

I’ve already attempted to handle this process on the client, however I still receive similar issues as well as faulty replication and security. Being handled on the server is the most viable option for me right now.

Here’s what I’m currently working with:

coroutine.wrap(function()
	local knockback_lifetime = 0.75;
	local impact_hitbox = vfxF_RS.general.knockback['object_impact_hitbox'];
	local force_delta = 500000; -- 500,000

	local body_velocity = Instance.new('BodyVelocity');
		body_velocity.MaxForce = Vector3.new(force_delta, force_delta, force_delta);
		body_velocity.Name = 'body_velocity';
		body_velocity.Velocity = plrCharacter['HumanoidRootPart'].CFrame.LookVector * 50;
		body_velocity.Parent = victim_character['HumanoidRootPart'];
							
	local impact_hitbox_clone = impact_hitbox:Clone();
		impact_hitbox_clone.Parent = victim_character['HumanoidRootPart'];
		impact_hitbox_clone:SetNetworkOwner(victim_character);

	local impact_hitbox_weld = Instance.new('Weld');
		impact_hitbox_weld.Part0 = impact_hitbox_clone;
		impact_hitbox_weld.Part1 = victim_character['HumanoidRootPart'];
		impact_hitbox_weld.Parent = impact_hitbox_clone;
	debrisService:AddItem(body_velocity, knockback_lifetime);
	debrisService:AddItem(impact_hitbox_clone, knockback_lifetime);
													
	knockback_manager = impact_hitbox_clone.Touched:Connect(function(object_hit)
		if (object_hit:IsDescendantOf(workspace['Azoth_WS'])) then
			if (object_hit ~= victim_character) or (object_hit ~= plrCharacter) or (object_hit ~= impact_hitbox_clone) then																				
				impact_hitbox_clone:Destroy();
				local impact_Anim = animationsF_RS.general.punch['object_impact'];
				local impact_Track = victim_humanoid['Animator']:LoadAnimation(impact_Anim);
										
				local impact_boolVal = Instance.new('BoolValue');
					impact_boolVal.Name = 'impact_immunity_bool';
					impact_boolVal.Value = true;
					impact_boolVal.Parent = victim_character['Convars'];

				local impact_weld = Instance.new('WeldConstraint');
					impact_weld.Name = 'impact_weld';
					impact_weld.Part0 = object_hit;
					impact_weld.Part1 = victim_character['HumanoidRootPart'];
					impact_weld.Parent = object_hit;
				debrisService:AddItem(impact_weld, impact_Track.Length);
				debrisService:AddItem(impact_boolVal, combat_wrapper.game_values.other_values[1]);
										
				impact_Track:Play();
				knockback_manager:Disconnect();
			end; -- object_hit ~= victim_character/plrCharacter condition.
		end; -- object_hit:IsDescendantOf() condition.
	end); -- impact_hitbox_clone.Touched()
end)(); -- coroutine.wrap()

The server will inherently be slower in seeing physics updates than clients because it cannot process them that quickly. Expecting immediate feedback on a physics-based event handled by the server won’t give you an accurate, instantaneous result.

2 Likes

I’m well aware that the server will be inherently slower - do you have any alternatives, or possibly a better way to replicate this on the client?

There is one way but I’m not sure how hard I would endorse it especially if it’s for a PVP game - giving network ownership of the target character to the client performing the knockback. This would give authority of physics calculation and replication to the attacker.

Besides that, every other way I know is bottlenecked by the server or network trips.

2 Likes

Thank you for your response! Perhaps I’ll rewrite this system to be handled on the client in a more efficient manner, I’ll update the thread once/if I have done so.

For now, I’ll leave you with the solution.

Sorry for the late update, but I ended up rewriting the foundation to be handled on the client. All previous issues have been resolved.