LookVector not accurate

Im trying to make a cannon that ragdolls and fires a player over a certain distance and to move the player I’m using a BodyVelocity, and making the Velocity the front of the cannon (lookvector) * math.huge. However when firing the cannon, the player moves to the right / left depending on the rotation of the cannon model.

Heres a snippet:

	char:WaitForChild("HumanoidRootPart").CFrame = cannonModel.CharDump.CFrame
	char:WaitForChild("HumanoidRootPart").Anchored = true

	wait(1)
	
	char:WaitForChild("HumanoidRootPart").Anchored = false
	
	char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.CFrame.Position, cannonModel.CannonModel.Part.CFrame.LookVector)
	
	game:GetService("RunService").Heartbeat:Wait()
	char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0) -- remove current momentum
	
	local BV = Instance.new("BodyVelocity")
	print(cannonModel.CannonModel.Part.CFrame.LookVector)
	BV.Velocity = (char.HumanoidRootPart.CFrame.LookVector) * math.huge
	BV.Parent = char:WaitForChild("HumanoidRootPart")
	
	Ragdoll.Create(char)

Ive tried to change character rotation to the LookVector, but the issue is more the fact that the LookVector isn’t directly forwards and more angled than it should be.

Clip of issue: https://gyazo.com/562f7272de4e4c1d830279c6f85f1b95

All help is appreciated! <3

3 Likes

You can try using WorldPosition instead for the lookvectors. Good luck finding a solution!

You could either try multiplying the second parameter in cframe.lookat by 100 to have a longer direction

CFrame.lookAt(char.PrimaryPart.CFrame.Position, cannonModel.CannonModel.Part.CFrame.LookVector * 100)

If that doesn’t work, the only other solution that i can think of is the cannon part’s look direction may not be facing up.

I tried * 10000 and it didn’t move, and i’m quite confident because i put a texture on the front and its the right face

lookAt’s second argument is the position of where the CFrame will point towards, and the LookVector of a part returns the direction, not a point in space like what you are imagining. Use lookAlong instead.

Because of this, since you are applying velocity that is the HumanoidRootPart’s LookVector, you are getting results that may be skewed. I would recommend using the cannon model’s LookVector instead.

do you mean like this?

char.PrimaryPart.CFrame = CFrame.lookAlong(char.PrimaryPart.CFrame.Position, cannonModel.CannonModel.Part.CFrame.LookVector)
	
	game:GetService("RunService").Heartbeat:Wait()
	char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0) -- remove current momentum
	
	local BV = Instance.new("BodyVelocity")
	BV.Velocity = (cannonModel.CannonModel.Part.CFrame.LookVector) * math.huge
	BV.Parent = char:WaitForChild("HumanoidRootPart")

Only one way to find out obviously.

hasn’t changed anything :<

https://gyazo.com/fe0096896fe55627abde1a0cf89d0a28

In both cases, your character is launching to the right. Are you sure your cannon part is positioned and rotated properly? Can you send an image of what your cannon looks like along with any invisible parts.

Edit: Also try unanchoring after you create your BodyVelocity or manually setting into a ragdoll-like state. It also may be due to the fact that humanoid models will tend to stay upright when possible. Secondly, look into BodyVelocity’s alternative: LinearVelocity, as those body movers are deprecated.


This is the cannon w all parts visible - green is camera lock part, blue is the part which the character is moved to, red is hitbox.
I’m not sure what you mean positioned and rotated correctly though - it should work no matter which direction its facing because it gets the cannon front face lookvector. il try the anchoring now :slight_smile:

Which one of these parts are your cannon parts exactly? Is it one of the invisible parts or the actual rectangle part? If it is the former, then you have to make sure that the orientation aligns with your cannon part. If it’s the latter, see if this line of code below (assuming your character is placed in front of the cannon).

BV.Velocity = (cannonModel.CannonModel.Part.Position - char.PrimaryPart.Position).Unit * math.huge

As a side note, it is hard to tell from the angles provided, but is the character actually positioned dead center of your cannon part?

In the end, LookVector is accurate, it probably just has to do something with the placement and/or orientation of the model and/or the humanoid behavior when being locked into position.

This is because you might rotated part wrong, use ConeAdornment to determine front face, then use correct vector

I found the fix - Using BodyVelocity somehow screwed it up. Using LinearVelocity now makes player go straight. Thank you all for the help! <3