Jump to content

Need help adding a dash when attacking to custom weapon

Recommended Posts

I'm new to modding and I am working on making a weapon that allows the owner to dash while using it but I have no idea on how to do it or where to start.  I have some ideas on what could make a pseudo-dash such as increasing the movementspeed of the character to a really high amount when the character is higher than X feet away.


If making a dash would not work, then I am open to having it teleport the user.  I would like these to be when the person clicks to attack something and not targetable on the ground (to avoid spamming dashes/teleports to increase mobility). 


I have searched the forums and I have had no luck looking for what I'm trying to make. 


Thank you in advance for any help people give :)

Link to comment
Share on other sites

For starters, you need a function that fires when the weapon is used


local Dash = function(inst, wilson, target)

    --all following code, if not told otherwise, should go here





local fn = function() --you already have this line


inst:AddComponent("weapon") --you already have this (I hope)

inst.components.weapon.onattack = Dash


Teleporting is easier. Here's my absolutely untested concept. It uses a while loop too, which tend to freeze the game:


local pos = wilson:GetPosition() --get current position

local pos2 = target:GetPosition() --get target position

local differ = pos - pos2 --the differences in coordinates


--now, you need to calculate how forward you want the player to get tp'd

local newpos = pos + (differ * 2) --twice the distance

local repeat = true


while repeat do

if GetGroundTypeAtPosition(newpos) ~= GROUND.IMPASSABLE then --valid ground! yay

repeat = false --you can stop now

break --don't continue to the next bit either


newpos = newpos - (differ / 10) --get closer to the target (eventually one would end up near the current position)



wilson.Transform:SetPosition(newpos.x,pos.y,newpos.z) --tp there (y is height, usually 0, and doesn't matter at all)

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...