This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello, first time asking something.

I am trying to spawn some kind of hand, like a grapple, between my character and where I clicked on the screen. On event, I create an instance of a Rigidbody with a CollisionShape2D that has a segment shape. I put the A variable of the segment on the character and the B variable on the mouse position.

Thing is, I don't understand how I can make my sprite fit this shape that is not know beforehand. It is hard to tell if my script is working when I can't see the segment.

Yes, I am very new to the engine. Maybe it's a simple problem and I'll be very grateful for an answer!

Godot version 3.3.2
in Engine by (15 points)

Do you have a graphical mock up? I don't understand what do you mean by segment shape created when clicked. Maybe a similar game video?

I tried putting an image that I think can help. I'll try to better illustrate what I'm trying to do in the first place. I'm trying to make a mechanic which is that when a player clicks on the screen, a line is created between the character and the position of the click.

I found that the SegmentShape2D shape for the CollisionShape2D node has two variable which correspond to the position of it's two ends, so my idea was to, on click, create an instance of an object with the segmentshape and modify it's variables so that they fit the character's position and the click's position. It might be a very inneficient way to do it, idk.

I could try sketching my idea, it's pretty clear in my head but I don't know how I can import the image in the forum.

Thanks for helping me

Other video game with the same concept kinda

Ahh, so its like a grapple! Well for position of two points you should use raycast as mentioned below in answer. Grapple is hard to implement if created shape is softbody. You can try softbody node. But I don't know how you can make it behave with two constraint or whether it will hold. As long as just drawing a line goes raycast will give you all the information you need.

1 Answer

+1 vote
Best answer

Check out RayCast2D. You will probably need to use its get_collision_point() to build your grapple. There's also a basic Ray-casting guide in the docs.

by (1,311 points)
selected by

Sounds good, thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.