How do I fix this stuttering?

I am trying to tween the player to look at a part. It works, but its buggy.
Here is a video of the issue:

I am currently posting this from my phone.
I will edit my post adding my code.
EDIT:

function turnCharacter(hrp,target)
	local angle =  CFrame.new(hrp.Position,target.Position)
	
	local TS = game:GetService("TweenService")
	local info = TweenInfo.new(1)
	local goal = {}
	
	goal.CFrame = angle
	
	local tween = TS:Create(hrp,info,goal)
	tween:Play()
end

I would also like to add that if I am under the net, I pretty much lay on the floor and face the net. Is there a way I can just make the character point in that direction, but not look up and down? Just kinda rotate in a direction on one axis.

3 Likes

You could apply RunService:BindToRenderStep() to this function

How would that help? Besides, doesn’t renderstepped not work on the server?

It would make it smoother. Yes it does work on the server.

How could I go about applying it to my code?

Also quick question, aren’t tweens supposed to be super smooth? I just wanna know why it is stuttering even though its just a normal tween.

It would be better to add a BodyGyro with RenderStepped instead of tweening.

I tried that. It sometimes rotated the player too much, or it would just not rotate them at all.

Edit, just re-read and saw the renderstepped part. How do I even add something like that when using body gyros?

Maybe it is because of collisions?

I think that is the issue, not the tween. But, how do I prevent the glitchy collisions from happening?

Also, the player points towards the net on all axis… is there a way I can just rotate the character to look at a part on only one axis?

You can loop through the character and turn off the collisions and after its done turn them back on.

Never use RenderStepped unless you’re updating the Camera or a part of the character such as their local transparency. Never use RenderStepped on the server, regardless of what you’re doing. In any case that you need RunService, always aim for Heartbeat or Stepped depending on how important your operation is to run relative to physics simulation (Stepped for before, Heartbeat for after).

2 Likes

I use a basic r15 rig in this game, and all of the parts already have CanCollide false. What else could I do to disable collision?

But if run service was the problem would the tween ever finish?

I think I know the problem. The glitchy collisions are happening because the HumanoidRootPart is being rotated on all axis. How do I just rotate the player on one axis, as if he were just turning in the direction of the net? At the moment he rotates up and down too. I don’t want that to happen.

Ultimately RunService’s relevance here is pretty small; the main issue is the “stuttering” which is coming from conflicting forces attempting to orient the Humanoid upright. The tween is fine otherwise.

Suggestion to OP is to negate any modification of the Y axis with the tween, that might be able to “fix” the “stuttering” effect that’s being shown. That means creating a CFrame while preserving the HumanoidRootPart’s Y. CFrame should be created with only the X and Y.

HumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(amount), 0)

Thats exactly what I want to do, negate the up and down movement. How would I turn this:

local angle =  CFrame.new(hrp.Position,target.Position)

to fit that criteria?

That would probably work, but how would I implement that into the humanoidRootPart’s position instead?

local angle =  CFrame.new(hrp.Position,target.Position)

Im thinking something like:

local angle =  CFrame.new(Vector3.new(0,hrp.Position.Y,0),target.Position)

(I don’t know if the code above works, just an idea… I only want it to tween that one axis to look at another part’s position.)

It actually appears that this code works by rotating me after testing:
local angle = CFrame.new(Vector3.new(0,hrp.Position.Y,0),target.Position)
but it also brings me to a random spot outside my map at this same time. Is there a way I can just make it so only that part of the HumanoidRootPart’s position gets affected?

Nope, its broken actually. It only works sometimes.

So the problem here is you are freaking out the humanoid. Try rotating its waist instead like roblox intended you for this type of stuff. If you are confused how to align two perpendicular vectors you multiply its cross and dots together.