up    |    index

ps1 rope physics

July 29, 2021

For the past few weeks I've been following a rope physics tutorial.

If you connect a bunch of masses together with springs and use a slightly altered version of Hooke's law [ F = -k * (x - d) ], you'll get a rope! I've only applied four forces to a total of 24 masses (23 springs) on the rope:

  • gravitational force
  • spring force
  • spring friction force
  • air friction force

Since I've neglected to add a ground absorption force, part of the rope that is in contact with the ground for extended periods of time will jitter. Also, instead of using a ground repulsion constant, I've simply deflected the vertical velocity of each mass when they are to collide with the ground.

a blue rope being simulated on a ps1 emulator

The constants provided in NeHe's tutorial didn't work for me, so I had to do some experimenting to get it to look good.

The hardest part was not the physics, but instead dealing with the dumb little quirks of fixed-point arithmetic. For example, whilst determining the unit vector, I wrote this (using 2^6-based numbers):

	(v.vx / r)>>6,
	(v.vy / r)>>6,
which prevented me from getting fractional values because I divided the whole damned thing by one. What I should've written was this:

	v.vx / (r>>6),
	v.vy / (r>>6),

convert the divisor to an integer and your answer will be a fractional number whilst remaining in the same fixed-point format.

Okay. So most of the degree2 engine has been rewritten with the addition of physics. Perhaps it's time to start another game project...