How do I maintain height and orientation of a part like an anchored part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m attempting to create a movement system for ships where players can control direction, speed, and elevation of their ship (if applicable).

  1. What is the issue? Include screenshots / videos if possible!

Videos:


I’m trying to make my target part (stand in for a ship)

  • Maintain elevation if some external force like another block hits it exerts force on it (As if it was anchored)

  • Maintain orientation and elevation if it hits a slope and tries to move onto it. Eg. boat hits a slope in the map, orientation should stay (0, y-value, 0) and its elevation shouldn’t change basically causing the slope to act sort of like a wall

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Here are some solutions I’ve considered:

  • PlaneConstraint (to prevent height changes), won’t really work because I’m planning on having ship types that can elevate and descend (ie. subs and zepplins) and if these ship types use the plane constraint to ascend and descend it’ll create a headache later on when dealing with the map and having these glitch into walls

  • Custom collision groups (attempt to deal with both) - have vertical invisible walls so that ships can’t change orientation or climb angled surfaces on the map; won’t work because of aforementioned ship types that could apply external forces to lower and raise other players’ ships

  • Checks every heartbeat to correct orientation and height of each ship on the map - seems quite inefficient and unnecessarily resource intensive

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here’s my setup for the ship part:

local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
linearVelocity.MaxForce = math.huge
linearVelocity.Attachment0 = attachmentMain
linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linearVelocity.Parent = boatPart

local vectorForce = Instance.new("VectorForce")
vectorForce.Force = Vector3.new(0, boatPart:GetMass() * workspace.Gravity, 0)
vectorForce.Attachment0 = attachmentMain
vectorForce.Parent = boatPart

local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Attachment0 = attachmentMain
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.RigidityEnabled = true
alignOrientation.Enabled = true
alignOrientation.Parent = boatPart

For movement, I adjust the linear velocity, and I rotate the cframe since changing the target orientation of align orientation seemed to cause a little bit of input lag when I tested it out. If there’s something I should adjust with this also please let me know!

I appreciate any help in advance!

Have you tried having invisible hitboxes on the parts which have vertical walls so the ships cannot change height when they try to push through them?

If you want other things to not collide with the obstructions, use collision groups and make the invisible hitboxes only collide with ships.

Hope this helps :slight_smile:

Hey, I was considering that as a solution, but then as I also detailed, Zepplins and submarines are going to be ship types that ascend and descend which could cause vertical movement if the players decide to ascend or descend below/above another player. It also wouldn’t deal with underwater obstructions.

Just an update for anyone in the future who may want to reference this: I think I have solved this issue by using a planeConstraint with Attachment0 set as the attachment at the target part and Attachment1 set as an attachment parented to Workspace.Terrain. When I want to change elevation I modify the elevation of the attachment parented to the terrain. This is definitely not the most optimal solution as I’m now having issues where the AlignOrientation’s target orientation seems to keep changing when the target part interacts with slopes. If anyone has a better solution I would still by very happy to hear and test out such solutions!