Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Tweening model in relative space?

Asked by 4 years ago

I've been tweeting models in roblox for a while now and it's always done in global space. Now trying to tween my player 5 studs forward from their current location as part of an attack move. I have no idea how to make the tween change from global to local. Is it possible to tween relative to the model?

1 answer

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
4 years ago
Edited 4 years ago

Yeppers, of course there is. Get the player's current position like this:

local CFrame = Player.Character.PrimaryPart.CFrame;

We use CFrame in order to maintain rotation. Just think of CFrame as a Vector3 with rotation properties.

We then add the CFrame's lookvector (multiplied by a constant, which is the distance) with the CFrame's current position. The LookVector is a Vector3 value (hence Vector), which means it can be added to a CFrame value, like this:

local Formula = (CFrame.LookVector * Constant) + CFrame;

Now, you can utilize TweenService to make the tween. We don't have to worry about using :ToEulerAnglesXYZ() here because we're maintaining the rotation values by adding a Vector3 to a CFrame.

TweenService:Create(Player.Character.PrimaryPart, TweenInfo.new(0.25), {CFrame = Formula});

2
Very nice. This helped me a bit, and it wasn't even my question. Psudar 882 — 4y
0
Thanks so much! I didn't think to use lookvector but it makes complete sense and I can configure this to get my desired effect. tygerupercut3 68 — 4y
Ad

Answer this question