Rjac // Rotating Joints According to Camera

Website built using Moonwave!!

Rjac

Rotating Joints According to Camera

What is Rjac?

Rjac (pronounced as “r-jack”) is an object-oriented module used to rotate character body parts according to camera direction.

For example:

Video 1

Video 2

This mechanic is used in a lot of games.
This is very simple to use with simplicity, flexibilty, and customization.

How to use it?

As I said it’s pretty simple to use but not very small, basic example:

local Player = game.Players.LocalPlayer
local Rjac = require(game.ReplicatedStorage:WaitForChild("Rjac"))

local RjacInfo = {}
RjacInfo.Player = Player
RjacInfo.Character = Player.Character

local Rjac = Rjac:New(RjacInfo)
Rjac.Enabled = true
Rjac:Initiate()

local Configurations = {
	{
		BodyPart = "Head",
		BodyJoint = "Neck",
		MultiplierVector = Vector3.new(0.8, 0.8, 0),
	},
	{
		BodyPart = "RightUpperArm",
		BodyJoint = "RightShoulder",
		MultiplierVector = Vector3.new(0.8, 0, 0),
	},
	{
		BodyPart = "LeftUpperArm",
		BodyJoint = "LeftShoulder",
		MultiplierVector = Vector3.new(0.8, 0, 0),
	},
	{
		BodyPart = "UpperTorso",
		BodyJoint = "Waist",
		MultiplierVector = Vector3.new(0.2, 0.2, 0),
	},
}

for _,v in pairs(Configurations) do
	Rjac:AddBodyJoint(v.BodyPart, v.BodyJoint, v.MultiplierVector)
end

game:GetService("RunService").Heartbeat:Connect(function()
	Rjac:UpdateDirection(game.Workspace.CurrentCamera.CFrame)
	Rjac:UpdateCharacter()
end)

{
	BodyPart = "Head",
	BodyJoint = "Neck",
	MultiplierVector = Vector3.new(0.8, 0.8, 0),
},

Now let’s break this down a bit and see what it means

BodyPart i.e "Head" is the name of the BasePart in the Character, where I will find a Motor6D, named the value of BodyJoint i.e "Neck".
MultiplierVector is the Vector3, which determines by what value will the joint be rotated.

There is only one way of fully understanding how to use this, which is by experimenting a lot with the module itself.

Taking a look at the Documentation is heavily encouraged to use the module to its full potential.

License

Mozilla Public License 2.0

Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work.

Read the full document here.

Installation

27 Likes

This module is useful in some games such as first person shooters or first person horror games or games where you want realistic mechanics in general. Good job!

Update

Nothing major:

  • Added a :Destroy() function, incase anyone needs it.
  • Went for a more direct approach to rotations rather than using BodyPosition for smoothness. No longer need to create a Folder named Rjac in Workspace.

Update

Build a website for this which contains the description and the documentation. Built using Moonwave. Man I gotta say that tool is soo useful!!

Seems cool but I can’t get it to work. I have a local script using the code sample you provided and the module script in replicated storage. I got this error in the console.

 Workspace.raahatu.LocalScript:40: attempt to call a nil value  -  Client - LocalScript:40
  15:39:45.602  Stack Begin  -  Studio
  15:39:45.602  Script 'Workspace.raahatu.LocalScript', Line 40  -  Studio - LocalScript:40
  15:39:45.602  Stack End  -  Studio

Can you share the local script which you have in the Workspace?

I used the same code that you provided in your example.

Sorry for that I forgot to update the script, UpdateBodyPosition is now removed, and replaced with UpdateDirection.

Alright it works now. Is it possible for this to run on r6 characters or just r15?

1 Like

It should work if you put the configurations properly. Haven’t checked though…

Could you please give an example of how you’d setup the configurations to satisfy an R6 character? R6 BodyParts do not have Motor6Ds which you use for the BodyJoints.

Alright so I have been working on R6 but simply changing the Configurations won’t work. I will try and get the module working for R6 but that won’t be anytime soon as I have exams coming up. I will return to developing around mid-February.

Is there any chance you could make this for R6?

Never seen a guy irl immitating narruto run while looking down but nice module!