How do i make bullet time travel using raycast. The issue is the raycast travels instantly
Theres multiple ways of doing it aslong as u have the start and end position of the bullet.
You could lerp it using this function
function lerp(a, b, c)
return a + (b - a) * c
end
where a is the start, b is the end and c is the time position
Edit: Or just do :lerp(goal,alpha)
Or you could tween it using the tweenservice
You could even use forces if you want to.
This module specifically just does the job for you and if you don’t want to then you could actually do some Calculation then Cast it Into the World, PS: @ItzPlanes method can work via TweenService
I quite don’t understand this function. Can you explain more?
Basically you input two positions A and B, and the function gets u all the positions between those two points based on the time C that you input.
like this (Mouse - Origin) * 1 ?
You’d have to do a for loop where you go from i = 0 to i = 1 and use i as the c value, and the position of the bullet would be set to lerp(origin,mouse,i)
In this case I recommend going for the tweenservice or the module that @FerbZides uggested though as they’re smoother and easier to use.
I think you pinged the wrong person.
Yep sorry about that! Ment to tag FerbZides
Also, can you explain that lerping function? I don’t understand.
me too i don’t really understand that function either
Its basically the same as doing Vector3:lerp(goal,alpha) which just moves a vector3 position to the goal using the alpha value, so for example if u use 0.5 for the alpha then you get half way from the vector 3 to ur goal, if you use 1 then you get from the vector3 to the goal and so on.
I propably shouldve just mentioned this instead of a custom function, I forgot you could do that
To avoid any confusion just go with the tweenservice, its better for this.
Can we like have a source code example?
A really simple solution could just be to add a delay on the raycast by calculating the distance. Of course this wouldn’t calculate for the velocity changes of the bullet while traveling.
i want it be as accurate by delaying how fast the raycast goes
man I feel you, im tryna figure out the same thing nothing helping me right now bro
Late response but I’d like to explain this to anyone who sees this in the future
With linear interpolation (Or lerp), what happens is the function calculates the point inbetween 2 points, based on an alpha value. This alpha value ranges from 0 to 1, 0 being the start, 1 being the end, and any number inbetween being inbetween the start and end
For example, with the basic lerp function:
function lerp(start, end, alpha)
return start + (end - start) * alpha
end
If start = 1, end = 10, and alpha = .5, it would get the halfway point between 1 and 10, which is 5. If it was something like .2, then it would return 2. We can use this in reference to the original topic by utilizing the alpha variable as the time variable. We can have a set start point and a set end point, and use CFrame:Lerp() to calculate points inbetween the start and end which can simulate time