The title is self explanatory, I want to make cockroaches/rats move like they move in real life using math, but I have no idea how to.
One of the things I considered using was bezier curves, but it wouldn’t be perfect I think.
Simulating the movement of cockroaches or rats in a game or simulation can be challenging since it involves many complex factors, such as the insect’s anatomy, behavior, and interaction with the environment.
One way to approach this problem is to break down the movement into smaller, more manageable components, and then simulate each component separately. For example, you could simulate the insect’s leg movements, body movements, and turning movements, and then combine them to create a more realistic overall motion.
Here’s a simple example of how you could simulate the leg movements of a cockroach using basic math and trigonometry:
-- Set the initial position of the cockroach
local x, y = 0, 0
-- Set the initial leg positions and angles
local frontLeg1X, frontLeg1Y = -10, 5
local frontLeg2X, frontLeg2Y = -10, -5
local middleLeg1X, middleLeg1Y = 0, 5
local middleLeg2X, middleLeg2Y = 0, -5
local rearLeg1X, rearLeg1Y = 10, 5
local rearLeg2X, rearLeg2Y = 10, -5
local frontLeg1Angle, frontLeg2Angle = 0, 0
local middleLeg1Angle, middleLeg2Angle = 0, 0
local rearLeg1Angle, rearLeg2Angle = 0, 0
-- Define the function to update the leg positions and angles
local function updateLegs(dt)
-- Calculate the leg movement based on time elapsed
local legMovement = math.sin(os.clock() * 5) * 10
-- Update the leg angles
frontLeg1Angle = math.sin(os.clock() * 5) * math.pi / 6
frontLeg2Angle = math.sin(os.clock() * 5 + math.pi / 2) * math.pi / 6
middleLeg1Angle = math.sin(os.clock() * 5) * math.pi / 6
middleLeg2Angle = math.sin(os.clock() * 5 + math.pi / 2) * math.pi / 6
rearLeg1Angle = math.sin(os.clock() * 5) * math.pi / 6
rearLeg2Angle = math.sin(os.clock() * 5 + math.pi / 2) * math.pi / 6
-- Update the leg positions based on the angles and movement
frontLeg1X = -10 + math.cos(frontLeg1Angle) * legMovement
frontLeg1Y = 5 + math.sin(frontLeg1Angle) * legMovement
frontLeg2X = -10 + math.cos(frontLeg2Angle) * legMovement
frontLeg2Y = -5 + math.sin(frontLeg2Angle) * legMovement
middleLeg1X = math.cos(middleLeg1Angle) * legMovement
middleLeg1Y = 5 + math.sin(middleLeg1Angle) * legMovement
middleLeg2X = math.cos(middleLeg2Angle) * legMovement
middleLeg2Y = -5 + math.sin(middleLeg2Angle) * legMovement
rearLeg1X = 10 + math.cos(rearLeg1Angle) * legMovement
rearLeg1Y = 5 + math.sin(rearLeg1Angle) * legMovement
rearLeg2X = 10 + math.cos(rearLeg2Angle) * legMovement
rearLeg2Y = -5 + math.sin(rearLeg2Angle) * legMovement
-- etc.
Thanks, what I meant by insect movement was the way the insects move in a random pattern tho, not the way their legs move.
Does the cockroaches have Humanoid or are they just a basic part?
they’re just a basic part on the floor
You would use AlignPosition
to move the parts.
I know, the problem is the math behind it, I want to know a way to get a random pattern of a cockroach moving, like they do IRL.