Jump to content

Create a projectile without the use of an inventory item or equipping in hand


Recommended Posts

Based on all the code I've seen, every single projectile attack is based on launching a weapon you have in hand. Even monsters will equip their projectile item before attacking. The problem is, I want a projectile to shoot out regardless of what is in the character's hand. 

 

What I want to do is have the character's attack range set to inst.components.combat:SetRange(6, 2) so that attack attempts will be made at medium range, but the attack will miss unless you're in normal melee range. I then have a listener for inst:ListenForEvent("onmissother", rangedattack) that will trigger when the attack fails. It will allow me to execute a normal melee attack, however. 

 

So, shouldn't my code be able to just spawn in a projectile, give it a trajectory based on my target, and launch? I've tried a bunch of things, but I'm running into all kinds of issues. SpawnPrefab("spit") doesn't seem to make it appear, even just staying in place, let alone trying to make it launch.

Maybe there's some way to quick swap what's in the player's hands, execute the attack, then swap it back? But then it'd probably play all the equipping noises and that'd be annoying...

Link to comment
Share on other sites

That's exactly what I needed! I had to modify the prefab spawn code a little since I'm calling it in character.lua, but it's functioning perfectly :D
 

local function rangedattack(inst,data)    local projectile = SpawnPrefab("spit")    projectile:AddComponent("weapon")    projectile.Transform:SetPosition(inst.Transform:GetWorldPosition())    projectile.components.projectile:Throw(inst, data.target)end

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...