#Fixed camera with 45 degree increments

1 messages · Page 1 of 1 (latest)

haughty talon
#

I have an idea for a character's camera that makes the character's camera fixed and rotatable between 35 degree increments with slight easing or interpolation or smthn (no snapping) and have NO clue how (the math's too advanced, and don't really know how to mess with the camera)

pulsar orbit
#

local cam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

local maxZoom = 25
local ScrollMulti = 2

task.wait(.5)

local NewCam = game.Workspace.NewPCamera

local function SetCamera()

cam.CameraType = Enum.CameraType.Scriptable

cam.CFrame = NewCam.CFrame

end

local function Scroll()

UIS.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseWheel then
        local Position = input.Position.Z
        
        if Position > 0 then
            if cam.FieldOfView - (1 * ScrollMulti) >= 70 - maxZoom then
                cam.FieldOfView -= Position * ScrollMulti
            elseif cam.FieldOfView - (1 * ScrollMulti) < 70 - maxZoom then
                cam.FieldOfView = 70 - maxZoom
            end
            
        elseif Position < 0 then
            if cam.FieldOfView + (1 * ScrollMulti) <= 70 + maxZoom then
                cam.FieldOfView -= Position * ScrollMulti
            elseif cam.FieldOfView + (1 * ScrollMulti) > 70 + maxZoom then
                cam.FieldOfView = 70 + maxZoom
            end
        end
    end
end)

end

local function CheckForMovement()

local KeysBeingHeld = {}

local TimeForSmooth = .1

local function SmoothMovement(NextStep)
    local info = TweenInfo.new(
        TimeForSmooth,
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.InOut
    )

    local tween = TS:Create(cam, info, {CFrame = NextStep})

    tween:Play()

    tween.Completed:Wait()
end

local function ContinueMovement()

    while true do

        local NewVelocity = CFrame.new(0,0,0)

        for Key in pairs(KeysBeingHeld) do
#

if Key == "W" then
NewVelocity = NewVelocity * CFrame.new(0,4,0)
elseif Key == "A" then
NewVelocity = NewVelocity * CFrame.new(-4,0,0)
elseif Key == "S" then
NewVelocity = NewVelocity * CFrame.new(0,-4, 0)
elseif Key == "D" then
NewVelocity = NewVelocity * CFrame.new(4,0, 0)
end
end

        if KeysBeingHeld["LeftShift"] then
            NewVelocity = CFrame.new(NewVelocity.Position * 2)
        end

        SmoothMovement(cam.CFrame * NewVelocity)
    end
end

UIS.InputBegan:Connect(function(input)

    local key = input.KeyCode.Name

    if key == "W" then
        KeysBeingHeld["W"] = true
    elseif key == "A" then
        KeysBeingHeld["A"] = true
    elseif key == "S" then
        KeysBeingHeld["S"] = true
    elseif key == "D" then
        KeysBeingHeld["D"] = true
    elseif key == "LeftShift" then
        KeysBeingHeld["LeftShift"] = true
    end
end)

UIS.InputEnded:Connect(function(input)
    local key = input.KeyCode.Name

    if key == "W" then
        KeysBeingHeld["W"] = nil
    elseif key == "A" then
        KeysBeingHeld["A"] = nil
    elseif key == "S" then
        KeysBeingHeld["S"] = nil
    elseif key == "D" then
        KeysBeingHeld["D"] = nil
    elseif key == "LeftShift" then
        KeysBeingHeld["LeftShift"] = nil
    end
end)

coroutine.wrap(ContinueMovement)()

end

SetCamera()

task.wait()

Scroll()
CheckForMovement()

pulsar orbit
haughty talon
haughty talon
# pulsar orbit put this into **StarterCharacterScripts**

" UIS.InputBegan:Connect(function(input)

    local key = input.KeyCode.Name

    if key == "W" then
        KeysBeingHeld["W"] = true
    elseif key == "A" then
        KeysBeingHeld["A"] = true
    elseif key == "S" then
        KeysBeingHeld["S"] = true
    elseif key == "D" then
        KeysBeingHeld["D"] = true
    elseif key == "LeftShift" then
        KeysBeingHeld["LeftShift"] = true
    end" 💔
#

cant you just use the magnitude

#

actually no

#

but js let me do ts

#

yeah doesnt work

#

woohoo

#

time for the debugging process

#

or js try again to do it

#

also misses some key points i made

#

in the question

haughty talon
#

⛓️‍💥❤️‍🩹

haughty talon
#

also the topdown camera u provided that i tested

#

doesnt work as topdown either 💔

#

but hey

pulsar orbit
#

yet it does 🥀

haughty talon
#

arguing against stupid people: they never admit defeat

#

so carry on

pulsar orbit
#

just angle a part named "NewPCamera" 🥀

#

thats all you have to do ⛓️‍💥

haughty talon
#

1, clearly disproven based on my camera experience

#

12th grade? im going into NINTH 😭

#

also

#

2:

pulsar orbit
haughty talon
#

im here BECAUSE i cant find a tutorial

haughty talon
#

guh

haughty talon
pulsar orbit
haughty talon
#

i did

pulsar orbit
haughty talon
#

1: Disproven, the math i need is not my grade level, infact beyond
2: No tutorials i can find, hence im here
3: ur cam script sucks ass

#

did you read what you wrote??

pulsar orbit
haughty talon
#
  1. no 🥀
  2. searched for the past couple o hours on devforums, youtube, etc
  3. "(top-down camera, the principals remain the same)", even yet still broken still spits out like 800 errors, etc
#

so yeah

haughty talon
#

" 'no' 🤡 "

#

did you read the question too

pulsar orbit
#

was this really that difficult?

haughty talon
#

a fixed player camera at an offset with 45 degree rotational increments with interpolation or tweens to prevent immediate snapping

#

💔

#

bro is <3rd grade ELA

pulsar orbit
civic elm
pulsar orbit
#

you are never going to find a tutorial that specific

haughty talon
#

i still figured it out hopefully 🙏

haughty talon
#

why do you think i am here

pulsar orbit
#

just make it yourself 🙏

haughty talon
#

gang

#

that's why im here

#

i do NOT kno how 🙏

#

read the question

#

i do NOT know roblox player camera manipulation

pulsar orbit
haughty talon
#

i have already spend long enough trying

haughty talon
ruby vault
pulsar orbit
haughty talon
#

ive spent the past 2 days reading docs and trying to make it work

#

i js restarted cuz it was that bad

pulsar orbit
haughty talon
pulsar orbit
haughty talon
#

i got some cool stuff to work with help

civic elm
haughty talon
#

because chat

#

i read the docs

#

interperet

#

and seek help (WHY IM HERE 😭

haughty talon
#

and this is one of a few cases my guy

pulsar orbit
#

ask help for simpler, less specific things, not "can you guys do my whole project for me"

haughty talon
#

yeah

#

but how do i do anything without a start 💔

#

i dont even kno what i am supposed to do my fella

#

and i looked at ur script

pulsar orbit
haughty talon
#

and honestly

#

💔 you cant be real

haughty talon
#

but i cant get shit that works but im supposed to make allat work somehow

#

1000 monkey typewriter methodry

#

do you realize

#

its okay to js ask for some help?

haughty talon
#

and ur like "but no wahh wahh not whole project"

#

my FELLA

#

my BROTHA

#

my ASSOCIATE

#

js let me ask for help

#

and im gonna say smthn so let me type this time

#

i read the docs, RIGHT? SO I LEARN RIGHT? How ive been taught is by reading, so obviously.

#

I then interperet as sich, apply the knowledge

#

and it works

civic elm
#

i still cant tell what youe asking

haughty talon
#

but when I cant figure it out, cant find a proper tutorial, etc,

civic elm
#

yea its too vague

haughty talon
#

I'm stupid for asking?

civic elm
#

lock the camera within a degree range?

haughty talon
#

kindaa

#

like

#

you have a locked view looking at char

#

i can kinda do that??

#

but

#

45 degree increments with tweening/interpolation

#

is giving me a fucking aneurysm

#

because my guy

#

i js dont get it

#

😲

#

and i need help 🤯

#

so im going to go back to trying ts 500 different ways and come back in another 2 days because apparently that's the right way to do it?

#

cyas

civic elm
haughty talon
#

like

#

when those games where you press < or > and it aligns the camera

#

but only that

#

and no snapping, but like

#

interpolate or tween it for a smooth transition?

#

because unless ur that one mariocart, more than 8 directions on a sprite is a bit crazy

civic elm
#

for a SPRITE?

haughty talon
#

for 2d in 3d

civic elm
#

what are u really trying to do

haughty talon
#

yk like baldis basics

#

where bladi is 2d

#

its that

#

but the angle changes

#

like the back and front of a sprite dependent on if ur looking from the back or the front

#

and the part i need help with

civic elm
#

but baldi always looks straight at you

haughty talon
#

is the camera that can look around

#

yeah ik

#

this is diff

#

the sprite follows, but the direction they're facing changes(??)

#

something like that

#

like yk og mariocart sprites?

#

let me get u a vid example

civic elm
#

like if youre holding a and w youre at a 45 degree angle

#

from the camera

haughty talon
#

you move

#

camera stays until moved by the q or e in 45 or -45 repsectively or what ever is left and right im js lost

civic elm
haughty talon
#

yk how

stable galeBOT
#

studio** You are now Level 8! **studio

haughty talon
#

the mariokarter

#

lets say

#

the direction is always flat to the camera, right?

#

but the drawing of the sprite rotates

civic elm
#

yea

haughty talon
#

like when u animate a 2d area and on that area a 3d object rotates

#

the 2d object is the enemy

#

but

civic elm
#

oh i see what youre tryign to do now

haughty talon
#

the enemy is able to face back and sideways etc

#

ye?

civic elm
#

yea

haughty talon
#

so yeah

civic elm
#

8 different 2d sprites, pick the one that makes the enemy look like its looking at you

haughty talon
#

yes

#

well

#

it would look in one direction but

#

the sprites would change based off of your direction

#

like a 2.5d i think it is?

civic elm
#

like the actual world gui is still facing one way but the sprite is changing

haughty talon
#

and those directions are those 45 degree increments

haughty talon
civic elm
#

i think you can pair each sprite(put them all in a table or something) with a direction that its facing(lets call this A for all of them) and then also take the vector pointing from the sprite gui to the player(lets call it B) and then iterate over each A vector and pick the one that has the highest value from the dot product A.B

civic elm
haughty talon
#

its player projecting their view of the sprite

#

but i see

#

i think?

#

but the perspective changing triggers the sprite (based on the 45 degree incremented camera i need) so it rotates away/towards based on the sprite's own view vector (prob js a part it points to ill do or smthn)

civic elm
# haughty talon but the perspective changing triggers the sprite (based on the 45 degree increme...

you should just be able to do some cframe math to make the directions paired with the sprites actually point the correct way in the world( enemy.CFrame.Rotation:PointToWorldVector(sprite_dir) .CFrame.Rotation just gets the cframe without position cuz its unnecessary for these unit vecotrs, and then PointToWorldVector pretty much makes it so that for example 1, 0, 0 would be turned into the RightVector for the enemy.CFrame and i hope you can extrapolate to the rest)

haughty talon
#

well

#

with point to world

#

would that be the sprite's own direction? (seperate from the part that rotates to the player)

#

because

#

let me say my thingy

#

the view of the sprite changes based on where it goes n stuff

#

sp

#

if the player sees it moving

#

it would see the front then when turning to see it walk away see its back

#

so idk man im just lost

#

its very complicated for me which goofy goober didn't understand and just berated me for it

civic elm
#

basically it will rotate the sprite vec that originalyl didint care about where the enemy is facing by how much the enemy is rotate

haughty talon
#

let me draw but i think thats right

#

and like

#

8-directionals

#

so ngl

#

its actually like how doom did it

#

i should have said THAT

#

HWEQETHETHBNA

#

but not really how they did it

#

the way im doing it is a far ways different

civic elm
#

npc is red, sprite direction chosen is blue, purple is the direction vector enemy->playre, player is green dot, you can see blue direction is the most aligned(dot product shows how aligned 2 vectors are) and why its chosen

haughty talon
#

yeah

#

like this, small part is the enemie's sprite's look direction

#

but

#

the big flat panel would turn to you

#

and show the apropriate sprite based on ur perspective

civic elm
#

yea

haughty talon
#

so yeah

#

so i needa make the camera, say when it updates

#

and since its an interpolation/tween

#

update the view 1/2 way thru

#

so when you turn

#

the npc looks like it's turning too

#

based on ur perspective

#

let me draw

civic elm
#

nothing should happen to the sprite when you turn your camera

haughty talon
#

yeah

#

because its kinda like a haptic snap on a nob

civic elm
#

the camera snaps onto the npc?

haughty talon
#

if half way below 45 and half way above -45

#

the view remains the same

#

yk

#

so when you turn ur camera (above the half-way-45)

#

it turns with you kinda???

civic elm
#

so if the player is roughly looking at the npc nothing happens, but if you turn too much, theres a lerp back to the middle

#

oh shoot i gtg

haughty talon
#

ill figure it out i hope

#

I'm back sorry for the afk, had to do stuff around the house

raw oyster
#

HI

haughty talon
#

ive been dead 😭

#

lots of stuff goin on

haughty talon
#

is this officially dead lmao'

#

back to the grind