Looking for assistance with camera manipulation

What I wish to achieve is something similar to this camera manipulation:

What I’m struggling with is obtaining a Vector value. The Vector value I would like to get is one that always opposes the locked on target, and is somewhat always behind the character.

Now what I mean is that the camera’s CFrame is not relative to the local player’s cframe but would be something similar to a position somewhat relative to the player’s position (So a point that stays 10 studs away from the character and 5 studs up in the y vector but always opposes the locked on target)

Red = Target
Grey = LocalCharacter
Green = Camera

Right now I’ve tried many formulas:
local cameraPos = (CFrame.new(Character.PrimaryPart.Position)*module.CFrame).Position + module.Position

CFrame.new((CFrame.new(Character.PrimaryPart.Position)*module.CFrame).Position, module.target.PrimaryPart.Position) * module.CFrame

But it seems to always stick to a relative axis or relative to the player’s orientation

Can you be a little more clear on what you are trying to do?

https://gyazo.com/5b8a09abfb109278dfc7096d6573b416

This is a example of the camera angle that I’m trying to achieve;

You can see the camera is always at a angle that opposes the target making it not relevant to the players orientation.

Ohh looks nice. I’m still not seeing the problem, I don’t understand what you need help with. Your original post wasn’t very clear

Sorry for being unclear; I want the camera angle like that.

To keep things simple I was wondering if it was possible to get 2 positions like

Pos1 = Player.Character.PrimaryPart.Position
Pos2 = Target.PrimaryPart.Position

Then get a direction from it:

(Pos - Po1).Unit * (Pos1 - Pos2).Magnitude

And then determine the Vector3 value of that

I’m not the best at positioning, but that doesn’t look wrong. Alternatively if you just want the camera to look toward the target you can just do this:

camera.CFrame = CFrame.new(camera.CFrame.p,targetPos)

Yes the issue is that I need to position the camera correctly first. My solution above does not work.

Oh you can try having a separate part that acts as the focus of the camera, that part will follow the player smoothly, and the camera will just keep looking at the target. Not sure about the additional positioning but that’s a good place to start ^^

I’ve already attempted that, thanks for trying to help though;

Currently I’m attempting this:

local module = {
	--> Target
	target = nil,
	
	--> Camera Settings
	CameraOffset = 5,
	["Position"] = Vector3.new(0,4,0),
	
	--> Camera Tween Settings
	TweenData = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
}

local startPos = module.target.PrimaryPart.Position
local endPos = Character.PrimaryPart.Position
local distance = (startPos - endPos).Magnitude
local cameraPos = (endPos - startPos).Unit * (distance + module.CameraOffset) + module.Position

But this is what happens when I play:

https://gyazo.com/61205903da4f6c286cb2d9a430a6a380

EDIT: It seems like everytime I attempt to get a direction it goes underground.

From watching and slowly rewinding the example video you provided , it almost seems like the camera is just lerping or tweening towards the character’s head

The camera is indeed tweening towards some sort of part relevant to the character but what I want to achieve is the position. Notice in the gif when the player is dashing (When the character is facing left) the camera does not change it’s cframe to adjust behind the characters head. What I need is that position that opposes the target but above the character.

EDIT: A simple line would be CameraPos = Character.PrimaryPart.CFrame*CFrame.new(0,2,-8)

But this would move the camera to stay always behind the character (If the character were to orientate the camera would as well and eventually the character would be out of site)

I got similar results to the gif above when I tested what I said above, just move the camera subject more to have more varying rotations.
https://gyazo.com/936cb89456a8f528bb589f2b7bb3d0d4
Code:

local subj = Instance.new("Part")
subj.CanCollide = false
subj.Transparency = 1
subj.Anchored = true

workspace.CurrentCamera.CameraSubject = subj

local t = tick()
game:GetService("RunService").RenderStepped:connect(function()
	workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.p,workspace.Target.CFrame.p)
	if tick()-t >= 0.2 then
		game:GetService("TweenService"):Create(subj,TweenInfo.new(0.2,Enum.EasingStyle.Linear),{CFrame = script.Parent:GetPrimaryPartCFrame()}):Play()
	end
end)

3 Likes

I see I didn’t understand what you meant earlier, it seems like you change the camera subject.

Fortunately, I’ve solved my problem:

local cameraPos = endPos + (endPos - startPos).Unit * module.CameraOffset + module.Position

The issue was Unit changed the Vector to something like 0,0,1 which sent me to the center of the world. Adding the end position (My Character Position) was the solution. That’s why I was under the world.

Thanks for your help.

1 Like

No problem. Happy to help when I can