Move relative to camera

You are making this way too complicated, why don’t you use alignposition and alignorientation like the guy above said, it works really smooth.

I am using align orientation and you’re right; it works beautifully. The reason I need that math is because I need to figure out every frame what exact direction the scooter should face so that I can set the align orientation to be in that direction

Well the alignorientation just aligns one part with an other or an attachment. In my mind I just imagine that you put the part where the camera should be in the character so it is relative to him without any code and then you just use the math to turn the scooter and the part with alignorientation does the rest with the camera without any code
Correct me if im wrong

here’s the quick video; you will see it moves in the direction expected, but it turns the opposite way ;-;. I am still using the same code; I just changed attachment orientations

Easy fix, just turn the attachment or part by 180 degrees (i hope its that easy).

turning it around for some reason makes the scooter just spin forever

Could you provide a video or something?

I have an idea; reversing the right vector

haha ya that worked for some reason

but there’s unfortunately one final issue

the physics have not been resolved; the scooter just slides up walls. ill attach a video

1 Like

When you rotate an attachment it rotates all the thing attached to it (if you have a part with attachment it rotates part) because that is its property, so I recommend using a part which is independent or put everything inside of player character.

Because alignorientation works with parts aswell or with attachment but that is the problem

I actually had someone help me with it a while ago by showing me how to reflect the velocity during a collision, but this is not always ideal: Linear Velocity Constraint Causes Undesired Behavior During Collisions - #28 by ShaShxa

Here is the video of this issue.

Probably because the linear velocity can use infinite force and i can see that the scooter is tilted a bit

You suggested using the AlignPosition, but I think that might overcomplicate in this case because I will have to do constant raycasts to figure out how the position should change every frame. Do you have any suggestions on what kind of constraint I can use in my case? It seems like LinearVelocity may not be the best choice.

For me it seems that everything is working fine, could you please check in the linear velocity or whatever you use the force that it can use because for some reason I have a strong feeling that that is the problem

You can find it in properties

I am going to sleep now so i will respond tomorrow and just in advance if the force that it can use to achieve the velocity is very high then turn it down but not enough so it can still go up hills but not 90 degree walls

1 Like

You were right! Thank you very much for your help. The MaxForce was set to infinity; changing it to something like even 10_000 fixed the issue. Overall, this was the solution (it was spread out over several responses):


Every frame, you can set the target CFrame to this:

...
if movement.projectedMoveVector == movement.projectedMoveVector and movement.projectedMoveVector.Magnitude ~= 0 then
  local lookVectorYComponent = (-movement.projectedMoveVector.X * targetCFrame.UpVector.X - movement.projectedMoveVector.Z * targetCFrame.UpVector.Z) / targetCFrame.UpVector.Y
  local lookVector = Vector3.new(movement.projectedMoveVector.X, lookVectorYComponent, movement.projectedMoveVector.Z)
  local rightVector = -targetCFrame.UpVector:Cross(lookVector)
			
  targetCFrame = CFrame.fromMatrix(
	scooterPhysicsBox.Position,
	rightVector,
	targetCFrame.UpVector,
	-lookVector
  )
end

alignOrientation.CFrame = targetCFrame

This will allow the scooter to turn as expected. When it comes to the collisions, the issue lies with the max force. Change the max force to something lower and it should work as expected.

1 Like

Great, that you answered I am glad to hear that everything works fine.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.