Let me explain.
So, i have a floating part. Something is moving under it. I can detect the part with raycasting (infact i need to).
If the part is moving in a straight line, that i can just copy over.
But if the part is rotating:
I need the floating part act like it’s physically on it.
So is there a way i can make this work? Some fancy math to look into? A feature?
Yeah but that’s where my brain shuts down.
I know i have to move and rotate it like it does when only friction is at play. But as to how, i don’t know.
function Update()
local RayOrigin = Body.Position-Vector3.new(0,Body.Size.Y/2-.5,0)
local RaycastResult = workspace:Raycast(RayOrigin, -Body.CFrame.UpVector*FloatDistance-Vector3.new(0,.5,0), raycastParams)
if RaycastResult == nil then
Body.BodyVelocity.MaxForce = Vector3.new(0,0,0)
Body.BodyVelocity.Velocity = Vector3.new(0,0,0)
Body.BodyGyro.MaxTorque = Vector3.new(0,0,0)
Grounded = false
else
local GroundPart = RaycastResult.Instance
local GroundVelocity = GroundPart.AssemblyLinearVelocity
--newly added local GroundAngularVelocity = GroundPart.AssemblyAngularVelocity
if not Grounded then
Body.AssemblyLinearVelocity = GroundVelocity
Grounded = true
Body.BodyVelocity.MaxForce = Vector3.new(MaxForce,MaxForce,MaxForce)
Body.BodyGyro.MaxTorque = Vector3.new(MaxForce,MaxForce,MaxForce)
end
local Distance = RayOrigin.Y - RaycastResult.Position.Y
local FloatVelocity = ((Distance^2)/FloatDistance-FloatDistance) * -1
Body.BodyVelocity.Velocity = GroundVelocity + Vector3.new(Move.X,FloatVelocity,Move.Z)
--this too Body.AssemblyAngularVelocity = GroundAngularVelocity
end
end
Can’t you create a part under the floating part, that’s unanchored, and make it follow that part rather than the spinning part,like you had shown on your third video.
This is a just a suggestion, not a solution,It might not work.
uhhh okay for the “move” i believe you can use magnitude to find the distance from the part the ray got and how far the main part is from the center of the part the ray got (if that made sense). from that you can use that to “move” the main part and then rotate it (which you already got down)
I understood, seems logical. But what if the part rotates from a point other than the center of the object.
Hold on, my brain kicked in. Can’t i just calculate the linear and angular velocity, from the magnitude of the point of rotation and the ray hit? Then i wouldn’t need to use CFrames. But how can i get the center of rotation? You gave me a boost.
nah it’s alright lol, okay soo, i think you could do that? a cheap way of doing this is just finding the motor and use that as the center. hmmm or i guess you could uh do some math and try to calculate the motor position and the center from the rotating part. then find the middle and use that middle as the center if the rotating part isn’t centralized
No i was thinking more dynamic.
This will be used in some action packed stuff, and if, for example, i stand on a truck, and someone steers, or if someone is pushing a cart with me on it, then that rotation is offset by who knows how many studs.
I figured out a way to do what we brainstormed together. Angular velocity to linear velocity and rotation. I’ll try it out with the motor and near perfect conditions to see how it performs.
But it’s late (1:05) and you’ve helped a lot.
Marked as solution and thank you for your time.