# Spinning Entities around Origin

## Recommended Posts

I've got this question and it's more of a math question (I just got into high school so please don't expect too much).

I have a entity that grabs nearby blocks (block entities like sand) and spins them around the entity. Kind of like a tornado that just spins blocks in circles.

How can I find the X and Z position of these spinning blocks based on - the position of the entity controlling these blocks, the radius/distance between the entity and the flying block and the rotation orbit?

I currently found something similar to this:

```this.targetX = this.posX + xMod*orbitRadius * Math.cos(orbitDegree);
this.targetZ = this.posZ + zMod*orbitRadius * Math.sin(orbitDegree);
```

but it didn't work (pushed out all the blocks outwards and that's all).

##### Share on other sites

Tried inverting the addition to pull in.  And add an addition inside the trig functions to rotate?

##### Share on other sites

Tried inverting the addition to pull in.  And add an addition inside the trig functions to rotate?

What?! I don't really understand..

What I'm trying to get is to have blocks orbiting around an origin. I'm not sure what math I have to do to calculate the position of where these blocks should fly.

##### Share on other sites

Oh, in that case just get the cos/sin of the axis, multiply it by the distance away, and add all of that to the central X/Z point.

##### Share on other sites

Oh, in that case just get the cos/sin of the axis, multiply it by the distance away, and add all of that to the central X/Z point.

Isnt that the same as the code i wrote?

##### Share on other sites

You are also multipying by xMod/zMod, no clue what those are or what the surrounding code looks like?

##### Share on other sites

You are also multipying by xMod/zMod, no clue what those are or what the surrounding code looks like?

Those two variables are multiplied. They are either -1 or 1. If the position is negative, the xMod and zMod will be negative. This is used to make sure they fly the correct direction. \

The surrounding code aren't really related to this. I was testing and trying to make it orbit. Basically we have an entity that is walking around. If the entity goes close enough range to a specific position, the position will pull the entity towards it orbiting around it. Kind of like a block that has massive gravity.

##### Share on other sites

Hmm, should not be too hard, done things like that before, but I have no code in front of me currently...

I pretty much do something just like it in my mechanics mod though for rotation purposes.

## 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.

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

### Announcements

×

• #### Activity

×
• Create New...