How to get a relative coordinate

Hello.

So I am almost done with my Clown van kidnap remake.

One feature of the clown van is that it always comes from the left of the player, no matter where they are.

So far, I can only get the van to come correctly toward the target humanoidroot, only when I am facing the same direction.

I basically want to make it so no matter where the player faces, the van will always come from the players left and will always be on a logical angle for a car to move

Here is an illustration of what I want to do:

If you use the negation of the RightVector of the player’s humanoid root part
(-Player.Character.HumanoidRootPart.CFrame.RightVector), then spawn the van at some multiple in that direction, for how far away it should spawn, you should be able to get it to show up where you want. Note that using just the negative RightVector will cause it to be in line with the player, so you may wish to make use of the FrontVector too, so you can move the van a some number of studs in front of the player.

(does that make sense? It’s a big block of text :frowning: )

1 Like

So I just looked up these vectors. In this case, these vectors would basically “change” with the humanoidrootpart, so no matter the orientation of the part, it would still always come from the same side, instead of being locked on a fixed cframe?

1 Like

Yeah

2 Likes

Okay, thank you. I will give you the solution, as soon as I get it to work.

1 Like

Alright! Let me know if you encounter issues with it.

2 Likes

Alright so while figuring these vectors out, I started with printing rightvector itself.

it displayed (1,0,0)

What does this mean? This is my first time trying to tween based on relative orientation, so i’m a bit confused on this.

1 Like

That means that the right vector of the player is entirely in the X direction. If you were to turn 90 degrees clockwise, it would be come (0,0,1), and for all other values it would move between, having the magnitude of the vector always being 1.

So would this mean that I’d have to change my van’s moving tween, which moves on the x axis?

I assume you want to tween the van from X studs to the left, and have it end up Y studs in front of the player?

Yeah correct. so what my script does right now is it spawns 50 studs away and when it spawns, it moves on the x axis until the X coordinate of the humanoidroot and the primarypart of the van are close enough.

How many studs away from the player does it need to get (before the van stops)?

if math.abs(primary.Position.X - playerroot.Position.X) <= 1 then…

this checks it. Then it stops and does the other stuff that it needs to do like open the door etc.

It might help if I provide a code sample:

local StudsLeft = 50
local StudsFront = 1
----

local HRP = game.Players.LocalPlayer.HumanoidRootPart
local PlayerCFrame = HRP.CFrame

local StartPosition = PlayerCFrame - PlayerCFrame.RightVector * StudsLeft + PlayerCFrame.LookVector * StudsFront

local EndPosition = PlayerCFrame + PlayerCFrame.LookVector * StudsFront
1 Like

Rightvector is not a valid member of CFrame.

RightVector, not Rightvector (assuming you wrote it exactly how it was show in the error)

Oh yeah I did, let’s see what it does now.

Okay, now the direction is the van is facing is correct, but now the problem is the tween, which always moves on the X axis.

What’s the code of the tween?

while task.wait(0.1) do
		local position = primary.CFrame
		local newposition = position + Vector3.new(2,0,0)
		local tween = ts:Create(primary, tsinfo, {CFrame = newposition})
		tween:Play()