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 🙏
#Ice Spear Skill pointing at mouse
1 messages · Page 1 of 1 (latest)
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
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...
You could also ask chatgpt to implement sine function to your lerp, really gives that smoothness effect
s1 how about u just commit leave server
if u cant do anything else besides suggest ai
then you shouldnt even be here
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
any other commments you'd like to add?
blud u dont apply for a higher rank
** You are now Level 7! **
it is applying bro, with your code and stuff
??????
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
Go make a ticket right now see what it says
my last application was so long ago, I don't get your point, I know people who are extremely good they just don't wanna go through the hassle of applying
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
bro, I clearly stated the sine function part with the ai, I'm not just telling him go use AI 😭
and pray it works
"im notjust telling him to go use ai" ye tell me how does AI implement sine without it being used
🤦♂️
okay vro
@thin pawn sorry about this 🙏
gl with what you're working on
was using it, not rly useful in this case
its cool, its not that serious lol
?? waste of computational resources + it won't look 100% the same on different fps
if you wanted it locked at a 60fps calculation you'd just multiply a set alpha by dt / (1/60)
there're a multitude of ways you can approach this from
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!
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.
👍
So basically, that code given IS dynamic
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.
bluds typechecking dt like it isnt inferred already 🥀

I like to directly have everything type checked no matter what
Not really, it’s very clean with bigger scripts
it isnt bt ok
You can easily look at something and instantly figure out what parameter or variable is what type
r u slow
local n = 5
dont tell me u have troubles
figuring out
the type of this variable
What if it’s a child of an instance
Or an instance in general
Obviously I’m not gonna type check something like false
Not in some cases
??????? ☠️
What if you’re passing the object as a parameter
also u typechecking everything makes refactoring harder
what, show example
we are talking about parts where it inferrs the actual type
ur giving random situations
What 🥀
local value: number = getValue()
``` what if ur getValue returns different type results
thats what ur doing
🥀
so if our alpha constant is 0.2 and we are at 60 fps we will get a result of .2 but what if we are below 12 fps wont the alpha go above 1 and will overshoot?
Which is why we clamp it from 0-1
And nobody is going to get anything below 30 fps unless your game is screwed
30fps is pushing it too
underestimating phone devices
Phones can reach 60-120fps easily
What are you talking about
That’s like modern phone standard
yea on newest phones lol
Not newest per say
get a phone from 2020 and it will struggle having 40
It wouldn’t struggle
It’s likely that it’d sit around there
And if you have good enough optimizations it’d go higher
ur not including optimizations
if game has no optimizations
phone can literally struggle
so easily
Yes that’s what I meant by “if your game is screwed”
I feel like that statement is pretty intuitive
no optimizations doesnt mean "Screwed"
actively doing bad practices
LOL
Which result in less optimization
WHAT
Yes it’s true, errors and bugs can stack very easily and lead to bad performance or memory issues
no its just standard, for example, pairs is valid, if ur using it doesnt mean ur game is screwed
That is the world of micro-op
micro or not, point is made
Bigger optimizations are priority before micro op
bug fixing corrects behaviour blud
yes in some sense it can result better performance
but these two are still different things
If you had a cache and it’s destroy method errors, the cache will infinitely expand
Memory is fucked
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)
i still made my point, no optimization doesnt mean screwed if its standard
like if ur making a weapon, and u dont create pool
for bullets
doesnt mean screwed
In a way it does
What if you have 100 people shooting at the same time
No pool = screwed in that case
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
Yeah, fps changes are linear and like a ragged line
Not some smooth curve
We need a linear equation to solve for the difference, not an exponential equation
what if u want it to be fast to slow?
But pooling is considered a micro op
pooling is not micro op what are u talking about lol
That’s what calling lerp a bunch of times does
thats the worst statement u made so far
It’s like micro op somewhat
not even close
🤷 you can say that I won’t really say much, it’s kind of both
but if we call it every frame by the constant 1/60 wont the change always be linear?
No.
The cframe (or whatever you’re lerping) change is exponential
The fps change is not
ohhhhh so when we first add the lerp change the next frame we add onto that change
ohhhhh ok that makes sense thanks
and for linear we wouldnt base it off its previous cframe then only its starting position?
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?
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
oh yea im dumb thanks bro ur the goat 👍
you should use a Spring instead of lerping. It’ll make it look way smoother!
Use a spring!
what do u mean by a spring is that an instance or something else
No its just a general term in programming for code that mimics the behavior of a spring
bouncy bouncy bouncy!
Spring module:
https://create.roblox.com/store/asset/71132874095126
Require auto-complete:
https://www.youtube.com/watch?v=ObDp5JlbmFI
Ever wanted to learn Roblox Studio & scripting? Check out my course:
https://bit.ly/LuaScriptingCourse
Use code CODE_LUAU for 33% off!
My linktree:
https://linktr.ee/crusherfire
Music us...
oh wow this is actually a super cool module thanks!
btw
** You are now Level 2! **