#Ice Spear Skill pointing at mouse

1 messages · Page 1 of 1 (latest)

thin pawn
#

As seen on the video, the ice spear follows the mouse. I want to make it so that it follows the mouse with a bit of delay, similarly to the light ray in Grand Piece Online . I was told to use LERP but I don't know how to implement it here. Another smaller issue (doesn't have to be solved but could be useful), is that with this method shown on the video, I am firing the mouse position every .1 seconds, this doesn't seem to be optimal. Any tips on how to make this optimised would be really helpful 🙏

eager coral
#

you could fire to server at the rate (or when mouse OR camera pos changed) you are now and fire back to clients at a slower rate

#

and client just interpolates

#

the cframe

#

making it smooth and delayed

covert latch
#

so basically here u can use the exponential function so that while dt (x in the graph) is super small the alpha (y value) will be big. You can change around the formula if u want it go from slow to fast etc...

naive forum
eager coral
#

if u cant do anything else besides suggest ai

#

then you shouldnt even be here

naive forum
#

its not really that I don't anything

#

its more of ai knows the math behind it

#

I did provide the way

#

You should treat ai as a tool to help you

#

also, my rank doesn't really say anything about me or my experience

#

Just because I don't apply for a higher rank, doesn't mean I'm literally s1

#

He might not have learned about the sine function at all

#

so he might not know how to implement it properly

naive forum
eager coral
floral cryptBOT
#

studio** You are now Level 7! **studio

eager coral
#

you submit code

#

they determine your level

#

stop bullshitting

naive forum
#

it is applying bro, with your code and stuff

eager coral
#

??????

#

did u not understand what i just said

#

you cant choose what level u are applying for

#

you apply for the category

#

send ur work

#

they determine your level

#

ur not fooling anybody

naive forum
#

Go make a ticket right now see what it says

eager coral
#

fair enough they changed it

#

regardless

#

youre still not above s1

naive forum
#

You haven't even seen any of my code and you are throwing accusations, like Idrc what you think but cmon bro you can do better

#

My point is that I never said for him to start vibecoding and use ai only, what I meant is for him to learn about the sine function to help smooth out the lerping even more

#

Saying go look in google for that information is the same logic

#

You're just interpreting it in the wrong way

naive forum
#

bro, I clearly stated the sine function part with the ai, I'm not just telling him go use AI 😭

#

and pray it works

eager coral
naive forum
#

🤦‍♂️

naive forum
#

@thin pawn sorry about this 🙏

#

gl with what you're working on

gusty seal
#

You could use LookAt()

#

Maybe

thin pawn
thin pawn
upper lintel
#

if you wanted it locked at a 60fps calculation you'd just multiply a set alpha by dt / (1/60)

upper lintel
#

two of the easiest are lerping or using alignorientation in coalition with alignposition

#

lerping can be achieved through calling the :Lerp() function on your CFrame

#
local RunService = game:GetService('RunService')

local Part = workspace.Part :: Part

local _60 = 1 / 60


local function update(
    dt: number )

    local delta = dt / _60

    Part.CFrame = Part.CFrame:Lerp(some_cframe, some_alpha * delta)

end


RunService.RenderStepped:Connect(update)
#

an example with lerping

#

lerp stands for linear interpolation, meaning the equation has a linear slope

#

alpha is the percentage of the way one matrix moves to the other (10%, 50%, 90%) dictated by an integer ranging from 0-1

#

from what i remember, the :lerp() method is only available in vectors and cframes, and numbers have their own separate function for it with math.lerp

#

if you still have trouble understanding, let's assume two vectors: a and b

local a = vector.zero -- 0, 0, 0
local b = vector.create(0, 0, 10)

local midpoint = vector.lerp(a, b, .5) -- 0, 0, 5
#

the same result can be achieved with Vector3

local a = Vector3.zero -- 0, 0, 0
local b = Vector3.new(0, 0, 10)

local midpoint = a:Lerp(b, .5) -- 0, 0, 5
#

alignorientation and alignposition is probably the best way to go though, but lerping works just as fine. if you wanna know that then let me know!

covert latch
# upper lintel ?? waste of computational resources + it won't look 100% the same on different f...

Could u clear up some of the problems with the solution just so I dont make the same mistake.
1.well yea it would look different since lower framerate will be more choppy and higher framerate will be more smooth thats what the dt is for no?
2.why would u cap it at 60? Some phones cant reach 60 fps and some devices can go wayy higher why not make it dynamic so both the lower end and high end devices can decide how it will rotate based on their framerate.

#

👍

upper lintel
#

Dt is a number that represents the time between the last frame and the current one

#

Therefore on higher fps, the dt is smaller, and the code is called way more often

#

This is what makes dt usable

#

However, using dt on its own is difficult, especially considering how small of a number it is

#

So instead of using dt alone, we opt for changing a higher number using dt, which is good; but then, it’d take some tweaking to get it in between 0 and 1, and the number would have to be very high.

#

Dividing it by 1/60 gives you a usable ratio that requires no tweaking, as you can comfortably sit at your own fps and use a number from 0-1, knowing it will look the same on all fps.

#

Why does it work? If you have 60 fps, the equation will give you 1. This means with an alpha of .2, the result is .2

#

On the contrary, 120 fps will give you 1/2

#

That .2 scales down to .1

#

Therefore making it dynamically changing

#

There is no way to cap fps on roblox, we can only find a ratio to make up for the differences.

eager coral
upper lintel
#

I like to directly have everything type checked no matter what

eager coral
#

worst use of typechecking ☠️

#

stop talkin to me chud

upper lintel
#

Not really, it’s very clean with bigger scripts

eager coral
upper lintel
#

You can easily look at something and instantly figure out what parameter or variable is what type

eager coral
#

r u slow

#
local n = 5
#

dont tell me u have troubles

#

figuring out

#

the type of this variable

upper lintel
#

What if it’s a child of an instance

#

Or an instance in general

#

Obviously I’m not gonna type check something like false

eager coral
#

WaitForChild inferrs it as Instance?

#

so does FindFirstChild

#

blud has no knowledge

upper lintel
#

Not in some cases

eager coral
upper lintel
#

What if you’re passing the object as a parameter

eager coral
#

also u typechecking everything makes refactoring harder

eager coral
upper lintel
#

How will findfirstchild help you then

#

myfunction(workspace.Part)

#

Example shown

eager coral
#

ur giving random situations

upper lintel
#

What 🥀

eager coral
#
local value: number = getValue()
``` what if ur getValue returns different type results
#

thats what ur doing

upper lintel
#

Im not gonna type check it there

#

I’m gonna type check the output of the function

eager coral
#

blud u literally said u typecheck everywhere

#

even "dt"

upper lintel
#

Parameters and returns yes

#

And some variables

#

If they aren’t inferred

eager coral
#

🥀

covert latch
upper lintel
#

And nobody is going to get anything below 30 fps unless your game is screwed

#

30fps is pushing it too

eager coral
upper lintel
#

Phones can reach 60-120fps easily

#

What are you talking about

#

That’s like modern phone standard

eager coral
#

yea on newest phones lol

upper lintel
#

Not newest per say

eager coral
#

get a phone from 2020 and it will struggle having 40

upper lintel
#

It wouldn’t struggle

#

It’s likely that it’d sit around there

#

And if you have good enough optimizations it’d go higher

eager coral
#

ur not including optimizations

#

if game has no optimizations

#

phone can literally struggle

#

so easily

upper lintel
#

Yes that’s what I meant by “if your game is screwed”

#

I feel like that statement is pretty intuitive

eager coral
#

no optimizations doesnt mean "Screwed"

upper lintel
#

Define screwed

#

Bug fixing is considered an optimization

#

So don’t include that

eager coral
eager coral
upper lintel
#

Which result in less optimization

eager coral
#

WHAT

upper lintel
# eager coral WHAT

Yes it’s true, errors and bugs can stack very easily and lead to bad performance or memory issues

eager coral
upper lintel
eager coral
#

micro or not, point is made

upper lintel
#

Bigger optimizations are priority before micro op

eager coral
#

yes in some sense it can result better performance

#

but these two are still different things

upper lintel
#

Memory is fucked

covert latch
# upper lintel Which is why we clamp it from 0-1

oh I think I understand so basically you are just using 1/60 as reference and comparing it with dt to determine if the last frame was either too fast or too slow. So the problem with the exponetial method was:
1.Very expensive since we would have to plug in values into an equation.(yea this makes sense)
2.You said it wouldnt look 100 the same on different fps? (im a bit confused on this part)

eager coral
#

like if ur making a weapon, and u dont create pool

#

for bullets

#

doesnt mean screwed

upper lintel
#

In a way it does

#

What if you have 100 people shooting at the same time

#

No pool = screwed in that case

eager coral
# upper lintel In a way it does

no, lack of optimization doesnt automatically mean "screwed", it just means it could be more efficient. a weapon without bullet pooling will still work in most cases

#

pooling just helps in bigger scale

upper lintel
#

Not some smooth curve

#

We need a linear equation to solve for the difference, not an exponential equation

covert latch
upper lintel
eager coral
upper lintel
eager coral
#

thats the worst statement u made so far

upper lintel
eager coral
#

not even close

upper lintel
#

🤷 you can say that I won’t really say much, it’s kind of both

covert latch
eager coral
#

pooling affects allocation, gc pressure and frame spikes

#

thats not micro at all

upper lintel
#

The cframe (or whatever you’re lerping) change is exponential

#

The fps change is not

covert latch
upper lintel
#

Yeah

#

It’s like .2 of .2

covert latch
#

ohhhhh ok that makes sense thanks

#

and for linear we wouldnt base it off its previous cframe then only its starting position?

upper lintel
#

Exactly

#

And increment the alpha by dt * some speed

covert latch
#

and what if u want to have different changes like elastic for example I assume you'd just have to make a formula for the more complex changes right?

upper lintel
#

I mean the formula is already given to you with math.lerp

#

You can use lerp programmatically to create any number of easings

#

It’s the same principle as linear animation

covert latch
#

oh yea im dumb thanks bro ur the goat 👍

ivory walrus
#

you should use a Spring instead of lerping. It’ll make it look way smoother!

covert latch
ivory walrus
covert latch
floral cryptBOT
#

studio** You are now Level 2! **studio

thin pawn
#

i ended up doing the lerping by myself

#

unironically ur comment was the most helpful