Velocity for some reason drags player around the point where its supposed to be instead of sitting there

I know it has something to do with the overshoot of the velocity and it now changing with position but I’m still curious as to what might be the issue.

crazy take - but what if its re-adding the velocity after u reached ur target (position)

or

could be the the grapple (i dont watch aot)

We can’t help much if we can’t see how you are calculating it.
Please copy/paste the script here with 3 backticks (```) before and after it so it formats properly.

Here’s a more detailed explanation of the problem and some possible solutions:

  1. Overshoot of Velocity: If the NPC is moving too fast and reaches or passes its target position, the overshoot can cause it to “overshoot” and then correct itself by reversing direction. This leads to jittering.
  • Velocity Correction: You need to account for velocity when the NPC is close to the target to avoid overshooting. One way to do this is to gradually reduce the NPC’s velocity as it approaches the target.
  • Linear Interpolation (Lerp): Instead of directly applying the velocity vector, you can use a method like Vector3.Lerp or Vector3:VectorToObjectSpace to gradually adjust the NPC’s position towards the target, smoothing the movement and preventing overshooting.
  1. Damping the Velocity: You can introduce some form of damping that slows the NPC’s movement as it approaches the target, reducing the likelihood of overshooting.Example solution using damping:

Copiar código

local targetPosition = target.PrimaryPart.Position + lead
local currentPosition = humrp.Position
local maxSpeed = 10  -- Adjust the max speed as needed
local dampingFactor = 0.1  -- Damping factor to slow down as we get closer to the target

-- Compute the direction to the target
local direction = (targetPosition - currentPosition).Unit
local distanceToTarget = (targetPosition - currentPosition).Magnitude

-- Apply damping
local speed = math.min(distanceToTarget * dampingFactor, maxSpeed)  -- Adjust speed based on distance to target
local velocity = direction * speed

-- Move the NPC
hum:MoveTo(currentPosition + velocity)
  • The dampingFactor here helps slow down the NPC as it gets closer to its target, reducing overshooting.
  • The speed is gradually adjusted based on how far the NPC is from the target, making it slow down smoothly.
  1. Velocity Threshold for Stopping: Another way to fix the jittering is to introduce a threshold for when to stop moving. If the NPC’s position is within a certain range of the target, you can stop moving and reset any velocity to zero, preventing any small oscillations.Example with a stopping threshold:

Copiar código

local stopThreshold = 0.5  -- Stop moving when within this distance of the target

if distance <= stopThreshold then
    -- Stop the movement and reset velocity
    hum:MoveTo(humrp.Position)  -- Keep the NPC at its current position
else
    -- Move towards the target as usual
    hum:MoveTo(target.PrimaryPart.Position + lead)
end
  1. Lookahead with Target Velocity (Lead): When predicting the target’s future position (leadBy), make sure the lead is proportional to the target’s actual velocity and not too large, as that can cause jittering. You might want to adjust the leadBy dynamically based on the distance to the target or the target’s velocity.
  2. Movement Calculation Fix: The NPC might be moving with a “choppy” or unstable movement because of how you calculate its position and target. Instead of applying the MoveTo function every frame, it’s often better to compute the next movement incrementally, ensuring smooth transitions.Alternative solution using MoveTo with smooth approach:

Copiar código

if distance <= 3 then
    WalkAnim:Stop()
    NPCProperties.target = target
    AI[AttackType](NPCProperties)
else
    -- Apply a smooth velocity with damping
    local targetVel = target.PrimaryPart.Velocity
    local leadBy = 7
    local lead = Vector3.new(0, 0, 0)

    if targetVel.Magnitude > 0.1 then
        lead = targetVel.Unit * leadBy
    end

    -- Adjust movement towards the target, using Vector3:lerp for smooth movement
    local desiredPosition = target.PrimaryPart.Position + lead
    local smoothPosition = humrp.Position:Lerp(desiredPosition, 0.1)  -- Smooth movement

    hum:MoveTo(smoothPosition)
end

Here, I’ve used Lerp to smoothly approach the target position over time. This will reduce jittering and create a more fluid movement.

Summary:

  • Overshooting happens when the NPC’s velocity is too high, causing it to pass the target and then correct.
  • Damping the velocity or smoothly interpolating (e.g., using Lerp) can help reduce jitter.
  • Stopping thresholds ensure that the NPC doesn’t keep moving once it’s close enough to the target.
  • Dynamic adjustment of target lead or prediction based on velocity can help prevent erratic behavior.

By tweaking the movement and velocity handling logic like this, you should be able to reduce or eliminate the jittering effect when the NPC detects or follows a target. Let me know if you’d like any further clarification!

I apologize for the wait, I was busy with other stuff but here is how I calculate it, Pos is the Position of the current placed hook

			local DistanceMultiplier = math.clamp(math.min(Distance / 10, 1),0.5,1)
			local LookVector = CFrame.new(Character.HumanoidRootPart.Position, Pos).lookVector
			local Multiplier = (Boosting and Settings.BoostSpeed) or 1
			Multiplier = Multiplier * 1
			local Velocity = LookVector * 120 * (Multiplier) * DistanceMultiplier + Orbit
			if not Leftorbit and not Rightorbit then
				Orbit = Vector3.new()
			else
				local Direction = (Leftorbit and ((Boosting and -90) or -110)) or Rightorbit and ((Boosting and 90) or 110)
				Character[PlayerData.OdmGear].ODMcore.GasThing.CFrame = CFrame.fromOrientation(math.rad(45),math.rad(Direction/2),0)
				if reeling == 1 then
					Orbit = (CFrame.new(Character.HumanoidRootPart.Position,Pos) * CFrame.fromEulerAnglesXYZ(0, math.pi / -2.4, 0)).LookVector * Direction
				end
			end
			BVelo.Velocity = Velocity * Momentum/70 * Boosting * reeling
			BVelo.MaxForce = OtherSettings.MaxForce --Vector3.new(90000, 90000, 90000)```

This just uses MoveTo, doesn’t really help me considering I have a velocity inside of the player that uses it for hooking.

Fixed, all I had to do was do the hooks/velocity on client