Hi, I am trying to make a orb system like they have in Pet Simulator X. I am mostly curious on how they’re made and the calculations used for the motion of them. I am currently trying to make a system like this and I’ve done a little amount but I don’t really know what the best way of going at making this is.
Currently I have a step function (that gets fired every hearbeat):
function Orb:_step(DT: number)
if (self.Anchored) then return end
self.LastPosition = self.Position
self.Velocity += self.Gravity * DT
self.Position += self.Velocity * DT
local Result: RaycastResult? = self:_raycast(self.LastPosition, self.Position)
if (Result) then
self.Position = Result.Position
self.Velocity = ReflectNormal(Direction, Result.Normal) * (self.Velocity.Magnitude * self.BounceMultiplier)
end
end
This is my Orb object class
local self = setmetatable({
Position = Position or Vector3.new();
Velocity = Vector3.new();
Acceleration = Vector3.new();
Gravity = Vector3.new(0,-workspace.Gravity,0);
OffsetToGround = 1;
Anchored = false;
BounceMultiplier = .5;
},Orb)
my guess is that it doesn’t have any other thing to do. it just slightly bounces off the wall and repeats it forever. i think that is how a normal roblox object would behave too, the only difference is that the shake is not visible. first of all, what do you want the ball to do instead of shaking?
i don’t want to mislead you because i am not an expert in this topic but i think you could try multiplying the BounceMultiplier with the orb’s velocity. if this doesn’t work or it is not how it should be, i can’t give any more information.
You could do an additional raycast and compare normals to see if you got in a corner, if so you stop simulating physics.
OR you can force the object to get shot away if you want more chaotic physics.
I am not pro at making physics engines but it seems like ur ReflectNormal thing causing all this, if the raycast shoots from center of coin then it may cause infinite loop of reflecting. You can try and make it so is raycast result is the same 2 times in a row it stops doing that. Like do
local tempResult = nil --Put this somewhere where it can't update beside result function
local Result: RaycastResult? = self:_raycast(self.LastPosition, self.Position)
if (Result) and (Result) ~= tempResult then
tempResult = (Result)
self.Position = Result.Position
self.Velocity = ReflectNormal(Direction, Result.Normal) * (self.Velocity.Magnitude * self.BounceMultiplier)
end
Not sure about that since its in the module script, but you can try and play all stuff i said above for your needs. Basically as i see it tried to bounce of surfaces even without having much Velocity, you can clamp the reflection number to 0.1 so if reflection velocity is less than 0.1 if won’t push any further.