Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello. I have a block that iterates through a 16x16 area for EntityItems, however, I want to add motion towards these entities that 'pull' them towards the said block. I have been trying to do this for quite a while, however, I cannot figure out the math behind it. Currently, I'm finding the relative position of the items from the block and trying to add motion based on this. However, this ultimately failed and I just get items that fly everywhere and look very buggy. Any help would be appreciated.

 

Thanks.

  • Author
        for(EntityItem item : items)
        {
            double moveFactor = 0.5f;
            double distX = this.pos.getX() - item.posX;
            double distZ = this.pos.getZ() - item.posZ;
            double distY = item.posY+1.5D - this.getPos().getY();
            double dir = MathHelper.atan2(distZ, distX);
            double speed = 1f / item.getDistance(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()) * moveFactor;

            if(distY<0)
            {
                item.motionY += speed;
            }

            item.motionX = MathHelper.cos((float)dir) * speed;
            item.motionZ = MathHelper.sin((float)dir) * speed;
        }

After more testing, this seems to work, however, the items teleport around in random directions. I'm guessing this is a syncing issue, however, I don't know how to actually fix that. Also, would there be any way to stop the items from stacking with each other, if so, how could I achieve it? 

Edited by unassigned

7 hours ago, unassigned said:

double dir = MathHelper.atan2(distZ, distX);

 

7 hours ago, unassigned said:

item.motionX = MathHelper.cos((float)dir) * speed;

item.motionZ = MathHelper.sin((float)dir) * speed;

Why are you using trig? If you just want to pull items to a spot then motion is [blockPos - itemPos] / someNumber. 

 

7 hours ago, unassigned said:

Also, would there be any way to stop the items from stacking with each other, if so, how could I achieve it? 

Doesn't look like there is a way to do this.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.