I am using a modified version of the displacement formula to simulate projectile physics.
local function x(x0, v0, a, t)
return x0 + v0 * t + 0.5 * a * t^2
end
local function v(v0, a, t)
return v0 + a * t
end
function physics:step(time)
self.position = Vector3.new(
x(self.position.X, self.velocity.X, self.acceleration.X, time),
x(self.position.Y, self.velocity.Y, self.acceleration.Y, time),
x(self.position.Z, self.velocity.Z, self.acceleration.Z, time)
)
self.velocity = Vector3.new(
v(self.velocity.X, self.acceleration.X, time),
v(self.velocity.Y, self.acceleration.Y, time),
v(self.velocity.Z, self.acceleration.Z, time)
)
end
i have a wrapper object which is supposed to add more functionality to the physics module.
local _physics = self._physics
_physics.acceleration = self.acceleration
_physics.position = self.position
_physics.velocity = self.velocity
_physics:step(time)
local raycastResult = workspace:Raycast(self.position, _physics.position - self.position, self.raycastParams)
if raycastResult then
end
initially, for collisions i thought about using raycasts but then i realised this would not work if the time i step by is too large.
The obvious solution is to break down a large step to smaller increments and update the physics that way.
however, I want to know if there is any way that I could skip this? is there any way I can simulate collisions without having to raycast tiny steps all the time?