dofile( "data/scripts/lib/utilities.lua" )

local entity = GetUpdatedEntityID()

local projectileComp = EntityGetFirstComponentIncludingDisabled(entity, "ProjectileComponent")
local player = ComponentGetValue2( projectileComp, "mWhoShot" ) or 0

if(player ~= nil)then

    local x, y = EntityGetTransform(entity)

    local component = EntityGetFirstComponent(player, "CharacterDataComponent")

    local controlsComponent = EntityGetFirstComponent(player, "ControlsComponent")

    local aim_x, aim_y = ComponentGetValue2(controlsComponent, "mAimingVector")

    local length = math.sqrt((aim_x*aim_x) + (aim_y*aim_y))

    aim_x = aim_x / length

    aim_y = aim_y / length

    local multiplier = 800

    local vel_x = aim_x*multiplier
    local vel_y = aim_y*multiplier

    ComponentSetValueVector2(component, "mVelocity", vel_x, vel_y)

    shoot_projectile_from_projectile( entity, "mods/spellbound_bundle/files/entities/projectiles/sword.xml", x, y, vel_y, vel_x )


end
EntityKill(entity)