Rocket Launcher Aim "Deteriorates" as Player Enters and Exits Animations

This is my first post on the forums and I’d consider myself a novice coder. My game is pretty simple, it’s mostly a collection of tools and models with some fun mechanics, nothing fancy.

I have some parts scattered around the map that allow the player to pose when they interact with them (think of XYZ Public Bathroom). However, the more the player interacts with these poses, the further off-aim the rocket launcher I put in the starter pack gets. For example, if a player poses and un-poses just a few times in a row, the rockets from the launcher will spawn about 5 studs up and 5 studs out from the player’s head each time they use it, making aiming difficult.

The rocket launcher is the same launcher that Roblox themselves posted in the Tool Box, albeit with some minor tweaks and a new model. The rocket direction is determined via lookVector and the spawn position is determined by the “hole” on the launcher from which the rocket would realistically fire from. It aims and spawns perfectly fine until the player poses.

-- Position the rocket clone and launch!
local spawnPosition = (Tool.Hole.CFrame * CFrame.new(0.2, 0, 0)).p
rocketClone.CFrame = CFrame.new(spawnPosition, Pos) --NOTE: This must be done before assigning Parent
rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
rocketClone.Parent = workspace
rocketClone:SetNetworkOwner(nil)

task.wait(RELOAD_TIME)

Meanwhile, the pose script I use snaps the player’s HumanoidRootPart to a specific location/direction based on the player’s scaling settings, to prevent too tall/short of characters from appearing to float or sink into the ground.

local root = plr.Character:FindFirstChild("HumanoidRootPart")

root.Anchored = true
root.Position = part.Position + Vector3.new(0, ((part.Value1.Value * hum.BodyHeightScale.Value) + (hum.BodyTypeScale.Value * part.Value2.Value) - (hum.BodyProportionScale.Value * 0.1)), 0)
root.Orientation = part.Orientation
animation:Play()

I suspect this is messing with the CFrame of where the rocket is spawning, but IDK enough about Cframes to fix it…

More code or some screenshots can be provided if needed

PS: I’m heading out of the house soon and may not reply quickly

local spawnPosition = (Tool.Hole.CFrame * CFrame.new(0.2, 0, 0)).p
rocketClone.CFrame = CFrame.new(spawnPosition, Pos) 

I’m not a pro either, but what is the .p at the end of the 1st line above?
Also, what is ,Pos for in the 2nd line?

I’m not sure what the .p is, I think it was part of the original code from the Roblox launcher.
Sorry for not clarifying the Pos, it was declared earlier in the code and forgot to include it:

local Pos = MouseLoc:InvokeClient(MyPlayer)

So the rocket’s spawning position is determined by mouse location, lookVector, and the location of the tool’s decorative rocket-grenade-hole-thing

Edit: Found what ().p is from another thread, it returns the Vector3 portion of a CFrame

Small update: I’ve found that the problem is the rocket launcher’s hole’s CFrame. All the other values that determine the rocket’s spawn position work correctly (mouse position & look vector). The player’s humanoidrootpart’s CFrame is also unaffected by posing, which is the only part of the player’s character that gets manually repositioned by the pose script. But for some reason the hole’s CFrame’s Y value gets higher each time the character poses, despite the hole itself not changing position in relation to the rocket launcher.

Fixed:
It turns out that manually positioning and orienting the HumanoidRootPart within in the posing script was causing some kind of disjoint between the client and server. After posing, the character model would look fine on the client side, but visiting the server side would show the player’s character standing several dozens of studs off and facing the wrong direction (depending on how many times the player posed). This would cause the server to register the rocket launcher’s CFrame differently and affect the aim.

For some reason, using the :PivotTo command on the character model fixes this, and uses less lines of code too! The rocket launcher now fires correctly now.

root.Anchored = true
char:PivotTo(part.CFrame + Vector3.new(0, (part.Value1.Value * hum.BodyHeightScale.Value) + (hum.BodyTypeScale.Value * part.Value2.Value) - (hum.BodyProportionScale.Value * 0.1), 0))
animation:Play()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.