Trying to improve the bouncing ball and rope example, but need help

I was working on a game idea based on what is shown in the “Bouncing ball and rope” example game.

I don’t like that the rope attaches to what ever “group” object that is closest to the ball. I wanted to be able to click on the object and have the rope go to that object.

I figured out how to get it to do that. But if I miss touching an actual object and hit empty space, the rope is drawn to the far left of the screen. I tried changing it so that if the touch was not on one of the “group” objects, it wouldn’t draw the rope, and that worked, but because I’m having the camera follow the object, very quickly your finger won’t be touching the object any more and the rope disappears.

I tried every event that revolved around touch, and none gave good results without creating a bigger problem. Any idea how to get the rope to attach to any object in a “group” that your finger touches, and then be able to dislodge it upon a second tap if tapped on anything not in the “group”, or if another object from the group, attach it to that?

Thanks!

You could find the closest object to the touch position, and if it’s within a given distance then draw the rope to it, otherwise delete the rope object.

Thanks. How do I do that? I’m still fairly new. I tried looking through events for distance, and the distance between objects seems to not give the option to use distance from touch.

I don’t think there is a rope object. I think it’s just drawn from the physics joint. So, I’m not sure how to tell it to delete it when it isn’t’ close enough to a “group” object.

The rope object is a Shape Painter, and it’s been renamed Rope.

Here’s an example of how you could get the closest object (Coin in this case) and draw a line between it and the player.

See if you can use these events, and combine them with parts of the rope example.

2 Likes

Thanks for the help, but after multiple days of trying different things, I couldn’t get it to work. I couldn’t find anything that let me put in “DistanceBetweenPosition”, so I tried anything that seemed even close to that, and nothing worked. Are you using the latest version of GD? I’m wondering if you have options to click on things that I don’t.

“DistanceBetweenPositions” isn’t available as a straight condition. When you select new condition, choose Compare Two Numbers (under Other Conditions tab > Other) and the DistanceBetweenPositions function will be available as one of the parameters.

Thank you. I had no idea.

I believe I have it done correctly now, but it’s still not working. Does this look correct to you?

That looks correct. On you Rope object properties, make sure to uncheck the box for “Clear the rendered image between each frame”.

It is not checked.
Do I have to have separate actions for using physics with linking? In other words, is what you suggested just for drawing, or does it also cause the player to swing?
I’m having trouble seeing how it would so I figured I’d better ask.

The code is just to show how to get the nearest object, and either draw a line or remove an existing one based on how close the object is to the touch point.

You’ll have to create the rope joint (physics) and keep track of where to draw the line between player and anchor object every frame that it’s valid.

I had a feeling that was the case. I had temporarily turned off the sections that came built into the example that gave it the link and the swinging, just to focus on trying to get the rope to work properly.

When I turn the back on that didn’t make the rope show up. With the instructions you told me to use, it shouldn’t matter whether the link is turned on or not, right?

I can’t figure out why it’s not working.

Any suggestions on what to try next to get it to work?

Could you do some debugging, to see which events are fired?

  1. In the parent event (where you with the trigger once in it) change the colour of MainChar or background to blue.
  2. In the event where the distance is < 50, change the colour of MainChar or background to red.
  3. And in the event where the distance is < 50, change the colour of MainChar or background to red.

When you play, which colour does the MainChar or the background change to?

I’m sorry, I’ve only been learning this program for a few months. When you say change the colour of MainChar or Background to blue. Do you mean change the color of the text in the events?

I don’t know how to do that. I also don’t know how to do debugging. I will google that.

No, use the action to change the tint (= colour) of the sprite or background. It’s only used as a visual marker to indicate which events are firing, but it’s a form of debugging. So it’d look something like :

BTW, debugging is a generic term, so googling it won’t bring up this method.

Oh! ok.

The only set color option I could find was for lighting.

But I used the command to make the player hidden to try in those 3 places, and it work on the touch is down, and the distance is greater. But, no where I clicked triggered the < 50 action.

To change background colour, look under “Other Actions > Scene” :

image

So the next thing to confirm is that your lines are visible.

Can you create a new event, with an “At the beginnig of the scene” condition, and draw a line from 0,0 to 300,300? It should create a diagonal line from top left that goes down and to the right.

That did draw the line

Did you create the rope object first, or did it already exist on the scene?

If it already existed, copy the “delete rope” and" create rope" commands from the < 50 action to this new event you created (placing it before the draw command).

The rope object did not exist in the scene.

So you’re creating it first in that new event?