Unsure how to use tween to rotate and how to rotate on a custom axis

I’m trying to use TweenService to rotate the bonnet of a car so it can open and close. Im using proximity prompt to trigger the event. I’m also trying to get it to rotate it on a custom axis rather than the axis of the meshpart.

Problem is I’m not sure how to rotate a part using Tweenserivce and I’m also not exactly sure how to make it rotate on an axis that isn’t it’s local axis.

The axis im trying to make it rotate on is somewhere around the attachment:

What I intend on it looking like when opened:
Screen Shot 2021-03-28 at 1.16.35 pm

1 Like

There’s a devhub article on essentially the same thing for rotating around an object:

Edit: TweenService might not work if the car is moving, so you might just want to manually cframe it every frame.

Alright thanks, I’ll take a look

Tweening is a good idea, although as said by @Pokemoncraft5290, it may not work as intended while the car is moving. CFraming manually is one option, but I think you should consider using HingeConstraints. Why? Because they are a more performant and much smoother option. Despite closest player being a network owner of that part, it will almost certainly bring up positive results.

You can read more about HingeConstraints by checking the link I posted, and there is also a number of other sources that can help you. At first, you may think that what I’m mentioning isn’t useful, because this type of cinstraint is usually seen in rotating objects.

While that is true, you can set actuator type to Servo, which attempts to rotate the object until it reaches specified angle, while respecting determined torque and speed. All you require are two attachments you carefully position and play with properties, apply some other properties through script, and your car hood will have an axle it can rotate around.

You have numerous options now. For instance, you can tween HingeConstraints to some extent, you can tween speed etc. If you are creating, for example, a car chase, where one person is on the run, and possibly hits obstacles from time to time, you can add a hood that gradually breaks, and moves up and down slightly with each “bump”.

You should be pretty safe against exploiters, but in case they somehow discover that part is unanchored and they can control it to some extent, you can always set network ownership to the server (BasePart:SetNetworkOwner(nil) ). However, physics is simulated by closest clients intentionally to not burden the server, so use that method wisely.

@WSB_Ape

PS: If you only intend to use the car hood while the vehicle is parked, perhaps rather use TweenService.

Take a look at this great tutorial, which explains how to achieve what you are looking for pretty well (rotating the root part - around the axle).

Yep, to add on here is a model which I made from the article which should help out with tweening in a circular manner which requires a special work around because in the article you need to change two CFrames at once, the hinge and the door.

	hinge.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0) -- rotate the hinge
	door.CFrame = hinge.CFrame * offset -- apply offset to rotated hinge

So here is my work around post with a free model I made of the example with an attachment created which denotes the pivot point.

Very insightful thank you! I’ll take a look into this before i wast just using tween and Cframe.Angle and math.rad and it wasn’t working quite right lol