+1 vote

Control nodes screenshot

I'm trying to create an inventory like in Resident Evil 4 with Control nodes. So I'm trying to implement rotation with the drag and drop functions in Control nodes

I keep a reference to the itemPreview and then do a rotation by 90 degrees everytime a button is pressed:

itemPreview.set_rotation(itemPreview.get_rotation() + deg2rad(90))

Now in the location where I'm dropping the item, I do some intersect tests between the item i'm dragging and all the other item rects. Everything works correctly before I rotate anything. After rotating, it seems to still be using the old rect positions(?) I'm not sure exactly what's going on. I hope the screenshot I included helps. And here's the code for testing whether I can drop an item or not:

func can_drop_data(_pos, data):
var canDrop = true

var items = get_children()

for item in items:
    if item == data.item:
    if item.get_global_rect().intersects(data.itemPreview.get_global_rect()):
        canDrop = false

return canDrop

screenshot link if it didn't work: https://imgur.com/a/nwS3x2m

Godot version 3.3.1
in Engine by (13 points)

1 Answer

0 votes

Looking at the docs for Rect2, rotation isn't mentioned at all. I think the rectangles aren't capable of being rotated. Unfortunately you might have to use Area2Ds for this.

by (7,190 points)

Yeah the rotation seems to be part of the Control nodes. Although the rotation variable is listed in the Rect section of the editor when using Control nodes...

I did find a workaround by switching to TextureRects and just having two textures. A vertical one and a horizontal one. When you press the rotate button I just swap between the two. I don't rotate anything, the Rect size just changes to fit the texture. I then change the Rect size to be (0, 0) so the box shrinks to match the size of the texture. This fixes all of my intersection issues.

I am considering just using Node2Ds instead for the inventory though... I would have to do the drag and drop stuff myself instead of using the Control functions but that's fairly easy. And I guess I can just instance a popup menu button on the Area2Ds for an options menu.

Anyways, thank you for answering.

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 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 webmaster@godotengine.org with your username.