LookVector is not displayed correctly, resulting in inaccuracy

i’m making an ability system, one ability is meant to knock enemies back by using a linear velocity
the direction of the linear velocity is simply the look vector of the enemy’s root part but flipped

the lookvector, however, is left and right, and also a red arrow
and unless i’ve been living in lies all my life, one of the BLUE arrows represent the look vector

the enemy moves to the left without flipping the look vector, and moves to the right when flipping the vector


i tried calculating the direction by simply giving the player origin, and then getting the direction of that and flipping it:
local direction = (playerOrigin - enemyOrigin).Unit * (-1)
but this resulted in the same error

i am really confused, and don’t know what to do

function utility.CreateLinearVelocityInPart(part: BasePart, direction: number, velocity: number)
	local attachment = Instance.new('Attachment')
	local linearVelocity = Instance.new('LinearVelocity')
	
	attachment.Parent = part
	attachment.Name = 'knockbackAttachment'
	attachment.Position = part.Position
	
	linearVelocity.Name = 'knockbackVelocity'
	linearVelocity.MaxForce = 999999999
	linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	linearVelocity.VectorVelocity = (direction * velocity)
	linearVelocity.Attachment0 = attachment
	linearVelocity.Parent = attachment
	
	return linearVelocity
end

function utility.ApplyKnockback(character: Model, classData: {string: any}, stunDuration: number)
	local knockback: number? = classData.abilityFlags.knockback
	if not knockback then return end

	local knockbackDirection = character.PrimaryPart.CFrame.LookVector
	local stunned = utility.GetGameplayValue(character, 'stunned')
	local damageResistance = utility.GetGameplayValue(character, 'damageResistance')
	local enemyData = enemyStats[character.Name]
	
	local baseVelocity = math.floor(knockback / damageResistance.Value)
	local enemyMass = enemyData.mass or 50
	local referenceMass = 50
	local exponent = 0.5
	
	local finalVelocity
	if enemyMass > baseVelocity then
		local scale = (referenceMass / enemyMass) ^ exponent
		finalVelocity = baseVelocity * scale
	else
		finalVelocity = baseVelocity
	end
	
	local velocityDuration = (stunDuration * 0.35)
	local linearVelocity = utility.CreateLinearVelocityInPart(character.PrimaryPart, knockbackDirection, finalVelocity)
	
	velocityDuration = utility.ConvertToDecimalPoints(velocityDuration, 100)	
	print(`Final knockback velocity is {finalVelocity}`)
	print(`Final velocity duration is {velocityDuration}`)
	
	--dService:AddItem(linearVelocity.Parent, velocityDuration)	
	if enemyData.canBeStunned then
		stunned.Value = true
		task.delay(stunDuration, function()
			stunned.Value = true
		end)
	end
end
1 Like

A bit unrelated but at the end of your code you never set stunned to false, instead its true again for some reason

i appreciate the enthusiasm, but this is not the root of my issue :sob:

Are you trying to knockback enemy in the direction of attacker’s lookvector?

close enough, i’m trying to knockback the enemy in the direction they are facing but flipped
but i suppose i could knock them back towards the attacker’s lookvector

huh… this doesn’t work either
hmm

i think it’s because i set the vectorvelocity to a number, (direction * velocity), instead of a vector3
gonna test that rn

maybe your enemy model is oriented the wrong way

try CFrame.RightVector or CFrame.UpVector and you can multiply by CFrame.Angles(0, math.pi, 0) to rotate 180 degrees

does enemy.HumanoidRootPart:ApplyImpulse(attacker.HumanoidRootPart.CFrame.LookVector * -NUMBER) work as intended?

Now thats painful to deal with

nope, regardless of what vector i use, the direction is always the same

i need to convert the direction into a vector3 it seems, on it

oh my god

this line was the problem

all i had to do was remove it, and not set the position of the attachment at all
bruh