Page 1 of 1

(REQUEST) How to Make a Rubberband!

Posted: Thu Feb 28, 2019 1:22 am
by IttaBaby
I wish to make a chase NPC that does not fall behind enough to trivialize him while making him slow down when close to give the player some time to get around obstacles.


On another note, should there be a request thread/board/ect. to keep me from spamming this place? I feel bad when I ask for help rather than contributing. :/

Re: (REQUEST) How to Make a Rubberband!

Posted: Sat Mar 02, 2019 4:54 am
by The Dwarven Digger
I think I could help, but I'll need some more information first.
1) How will this NPC chase the player?
2) Will they copy the player's movements or continually move in a single direction?
3) Will they pass through blocks ,overcome the obstacles themselves or just break through the obstacles?

Re: (REQUEST) How to Make a Rubberband!

Posted: Sat Mar 02, 2019 2:43 pm
by IttaBaby
Currently he's just a re-skinned spiny, so walking forward while you make it around terrain. But having him break the terrain too would be cool.

Re: (REQUEST) How to Make a Rubberband!

Posted: Sun Mar 03, 2019 8:27 am
by The Dwarven Digger
Could you also PM me a download link for the level and any custom graphics etc. that go with it? If I have the layout that will help see how the NPC will have to behave and what obstacles there are, which could affect how the code works.

Re: (REQUEST) How to Make a Rubberband!

Posted: Sun Mar 03, 2019 9:02 am
by Hoeloe
Just as a note, I've used rubber banding techniques previously, and created an equation to determine the speed of a rubber banding object:

speed = s*(S/s)^(d/D)

Where:
S is the maximum speed of the camera (i.e. player runspeed)
s is the minimum speed of the rubber band
D is the maximum distance the rubber band can be from the player
d is the current distance the rubber band is from the player

And obviously, * is the multiply operator, / is the divide operator, and ^ is the power operator (in Lua that's math.pow).

This creates an exponential rubber band that slows down as it gets close to the player, but ensures it never gets more than a specified distance away. How to actually implement this is up to you, but the equation is there should you want it.