Dog on Leash Math problem....
I have a dog character I want to stay within some bounds when following the main character walking around the field: the dog is either tied up to a rope or in a fenced area. When the character walks away from the area, the dog will go back to the center of the area.
I've tried to constrain the dog to the area, but when the constrain changes to the character temporality to follow it, the dog leaves it's circle. I have also built invisible blocks around the area with a collide statement, but that didn't seem to work either because it will ignore the collide statement to follow the character. I've seen the eyeball example where it takes and rotates an image to point to the character but doesn't work for this example because I want it to smoothly go back to the center when the character leaves the scene.
I'd love to understand how to make this work with a circle and other shapes.
Thanks Community.
-LewisOne (My Website, FB, Twitter, IG, YT)
Comments
I'd be quite tempted to split this problem up into two or three elements rather than getting the dog to work its movement magic with a single fiendishly complex equation.
Assuming a dog on a leash (circular limit to its range of movement) . . . .
You can detect whether the main character is near enough to the dog to activate the dog moving towards the actor with the magnitude function - i.e. if magnitude (between dog and man) is less than - for example - 200 pixels the dog does his thing and moves towards the actor . . . but only if the dog's magnitude (between the dog and the centre of its circle) is less than 100 - to stop it leaving its area.
Otherwise interpolate the dog back to the centre of the circle.
Here might be a way to approach it.
Excellent ! And weird !
I tried exactly the same approach (I even used the same 200 pixel value for the enemy's proximity ! ) but the problem I had was that the dog would 'stick' on the permitter of his area - the area was defined in the same way (vectorToAngle( game.enemyX - self.Position.X , game.enemyY - self.Position.Y )) . . . ?
Maybe you used a better breed of dog ?
Just used a standard brown boxer. Get it... boxer... boxer? Brown box... boxer? Ah... um... never mind.
The dog lunges because the rule contains a behavior in the otherwise section.
Joke reported to the joke police, expect a knock on the door.
Yeah, I put an interpolate in there to return the dog to the centre of his area, that was probably something to do with it . . .
My first dog ran away from home, but the new dog RThurman put together gets me closer to the mark. Great solution. Thanks guys, a better dog breed was the answer.
-LewisOne (My Website, FB, Twitter, IG, YT)
@lewisone -- First time I've ever been accused of good breeding!
Glad the demo will work for you!
-RT