GithubHelp home page GithubHelp logo

pyseph / clientcast Goto Github PK

View Code? Open in Web Editor NEW
17.0 1.0 2.0 1.15 MB

An efficient, simple and modern solution to melee hitboxes.

Home Page: https://pyseph.github.io/ClientCast/

License: MIT License

Lua 100.00%

clientcast's Introduction

Table of Contents

Introduction

ClientCast is a simple and elegant solution to handling weapon hitboxes. This module is written with efficiency, simplicity and customizability in mind. This module is meant to be bareboned. ClientCast relies solely on raycasts to provide with hitbox data, and as such is not only extremely efficient, but also provides detailed information on where and when it hit an object. If you would like to get extra data or add your own functions, the best solution would be to simply wrap the object and add your own methods onto it.

The main forte of ClientCast lies in the fact that you can easily communicate with the client, letting the client handle all the calculations and then have the server be notified whenever the client intersects something. This allows the server to have to calculate way less and also take into account for a player's ping or delay, providing all players a lag-free experience.

Example Usage

Making a part kill players

Simply parent the ClientCast folder to ServerStorage and run this script on the server:

local ClientCast = require(game.ServerStorage.ClientCast)

local KillPart = Instance.new('Part')
KillPart.Anchored = true
KillPart.CanCollide = false
KillPart.CFrame = CFrame.new(0, 1, 0)
KillPart.Parent = workspace

function GenerateAttachment(Position)
	local Attachment = Instance.new('Attachment')
	Attachment.Name = 'DmgPoint'
	Attachment.Position = Position
	Attachment.Parent = KillPart
end

for X = -2, 2 do
	GenerateAttachment(Vector3.new(X, Y, Z))
end

local ClientCaster = ClientCast.new(KillPart, RaycastParams.new())
local Debounce = {}
ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
	if Debounce[HitHumanoid] then
		return
	end
	Debounce[HitHumanoid] = true
	print('Ow!')
	HitHumanoid:TakeDamage(10)
	
	wait(0.5)
	Debounce[HitHumanoid] = false
end)
ClientCaster:Start()

Note: This will not work until the part starts moving around.

asciicast

Setup

To start using this module, simply put attachments called DmgPoint (name is customizable in the Settings table at the top of the ClientCast ModuleScript) inside the object, and then create a ClientCaster object, with it's Object set to your hitbox. Example:

-- Call module
local ClientCast = require(PATH.ClientCast)
-- Create ClientCaster object
local Caster = ClientCast.new(workspace.Part, RaycastParams.new())

-- Connect callback to 'Collided' event
Caster.Collided:Connect(print)
-- Set owner of ClientCaster, who will be the one to calculate collisions.
-- You can skip this if you want the server to be the owner.
Caster:SetOwner(Player)
-- Start detecting collisions
Caster:Start()

Links

clientcast's People

Contributors

pyseph avatar baileyeatspizza avatar hatmatty avatar

Stargazers

 avatar Albertz avatar  avatar 28Y8 avatar  avatar Ray avatar  avatar Vezipe avatar  avatar  avatar David avatar  avatar  avatar Jesse Savary avatar  avatar miguel avatar

Watchers

 avatar

clientcast's Issues

Memory Leak?

In ClientCast, line 105; stopping the ReplicationConnection is delayed by 1 second.
If you implement a cooldown/swing duration of less than 1 second, then the caster can be started again before the old one is stopped.
This means the old connections are never broken because of a condition which checks if the connection is still the same, which is not met because the cast is started again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.