Detecting a parts rotation

Hi, I’m trying to figure out how to detect the cars orientation/rotation so I can place items in the correct locations. Here is what I’m talking about:

Would anyone know where I can look into or how to code this?

1 Like

You can add an invisible part as a primary part that holds everything then set model’s primary part to that part and place your items based on that.

1 Like

I was thinking to add that as my alternative. Thank you for the suggestion!

That didn’t change anything. If I drove forwards, the item was infront of me. If I went the opposite direction, it’d be behind me

I’ve noticed something, the part that’s welded to the car that holds items orientation isn’t changing as the vehicle moves, how can I fix that? If i can get that part’s orientation, I can place the item accordingly.

I’m having a little trouble understanding your question, are you asking how to get the orientation of the car? as to get its direction of travel or something or are you just wanting some system to tell your game when and where to place item drops?

It’s hard to explain, I’ll draw it out for you:

The arrows represent the direction the car needs to go. How can I detect whether they are going these directions and if the player decided to go the wrong way, it can detect this?

The orientation of the car doesn’t update, is there anyway I can fix this as well?

It looks like you’re making a racing game and you wish to notify the player if they are moving in the wrong direction. I suggest looking at the Dot product (I’ve personally never used it).

Here’s a video example for an NPC’s field of view.

That’s not what i wanted, though I’ll take a look at it. What I need is depending on the direction the player is moving, the item will be placed correctly behind the player. It’s correct if you are moving one way, but the other 3 directions are wrong

Which item are you referring to?

You can define your track as a collection of vector fields describing a “wrong” direction, then actively take the dot product of the car’s CFrame’s LookVector and the occupied field to determine whether or not the car is facing the wrong direction. Using this method you are able to fine-tune which rotations are considered incorrect and vice-versa, but it does take a basic understanding of vector math to grasp (and a more in-depth understanding to execute).

Okay, so the player can use items, for example, let’s just say a banana peel. The item usually gets placed behind the player. The issue is if the player is driving a different direction, it won’t get behind him, it’ll go in front, left, or right. How can I fix this?

You should utilize CFrame. Could you show me your code for what you’re doing?

That’s what i’ve been using:

game.ReplicatedStorage.Events.UseItem.OnServerEvent:Connect(function(player, item, playerid)
	if item == "OilSpill" then
		local itemname = game.ServerStorage.Items:FindFirstChild(item)
		local itemclone = itemname:Clone()
		itemclone.Parent = game.Workspace

		local playerkart = game.Workspace:FindFirstChild(playerid)

		itemclone.CFrame = playerkart.ItemHolder.CFrame + Vector3.new(-10,-1,0)

		game.ReplicatedStorage.Events.ItemUsedRemote:FireClient(player)
	end
	
end)

This here is the issue, you should be multiplying by CFrame not a Vector3. What I recommend doing is this:

itemclone.CFrame = playerkart.ItemHolder.CFrame *CFrame.new(0,0,0)

With this, it should spawn right on top of the itemHolder. Now what want you to do is just input numbers into each axis (x,y,z) and see how increasing the value will affect the position of the item. Just keep testing until you’ve got it!

1 Like

Wow, that makes a difference! I’ll take a look into it and solution your post if it works out. Thank you for your help! <3

Just use CFrame to detect orientation.

local car = script.Parent
local CarCFrame = car.CFrame

local NewBlock = Instance.new("Part")
NewBlock.Parent = workspace
NewBlock.CFrame = CarCFrame
1 Like