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.
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).
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.
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.