Search In
• More options...
Find results that contain...
Find results in...

# [1.16.5] Formula for brake force

## Recommended Posts

Hey guys,

I am struggling a long time to figure out how to create a formula for my mod.

Overview:

I created a brake rail which should brake down a minecart when it's on it.

I found this formula in the internet and applied it:

Spoiler
`this.currentBrakeForce = (Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)) / (2 * brakerunLength)`

The minecart has an entry speed of 12m/s, the target velocity is 8m/s and the break run is 1m because it's one block.

I slow down the cart by multiplying the result of this formula with the current motion of the cart:

Spoiler
`train.setMotion(train.getMotion().multiply(this.currentBrakeForce, 0, this.currentBrakeForce));`

I figured out another thing: The wiki says that that 8m/s are 1.2 in motion.

So I changed the formula depending on the motion (I don't know if this is right but it made sense to me):

Spoiler
`(0.15 * entryVelocity) / Math.abs(((Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)) / (2 * brakerunLength)));`

Why 0.15?

As mentioned before 8m/s are 1.2.

So, 1m/s = 0.15 -> (8/1.2).

And then I multiplied it with the entry speed because it has to be changed to the "motion internal unit"?!

I am really frustrated right know, because I tried a lot of different changes within the formula. The problem is maybe the multiplication with the motion? I don't know.

Maybe someone can help me

##### Share on other sites

3 hours ago, J3ramy said:

The wiki says that that 8m/s are 1.2 in motion.

Not sure where you're seeing this. BTW, minecarts already have a maximum speed of 8m/s per axis.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

Maybe I should mention it. I changed the max speed and max speed on rail to 16m/s.

But my question is more, how do I convert the calculated force to the Minecraft motion?

##### Share on other sites

Not sure, I haven't dug into the minecart code that much.

The only problem I see is that this:
Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)
Is guaranteed to return a negative value, which when multiplied against entity motion would cause the entity to reverse direction.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

Yeah I tried it with Math.abs but it isn’t working either…

##### Share on other sites

I might have understood it wrong, but if you are simply multiplying the x and z component of the velocity vector, then don't you just need the ratio between the target and entry velocity? So shouldn't your brake"force" be targetVelocity/entryVelocity?

##### Share on other sites

Hey Thorius,

I will try it tonight when I’m at home again but it seems like it could work. I’ll keep you up to date

##### Share on other sites

Finally I managed to check it.

It works perfectly.

Thank you all!

##### Share on other sites

You should know that this formula will also accelerate the carts to the specified speed. If you want to avoid that, use Math.min(brakeforce, 1).

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

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

×

• ### Posts

• Wrote the following code and passed the serializer through a deferred register: public class ModLoot extends LootModifier { protected ModLoot(LootItemCondition[] conditionsIn) { super(conditionsIn); } @NotNull @Override protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { generatedLoot.add(new ItemStack(Items.NETHERITE_SCRAP)); return generatedLoot; } public static class ModLootSerializer extends GlobalLootModifierSerializer<ModLoot> { @Override public ModLoot read(ResourceLocation location, JsonObject object, LootItemCondition[] ailootcondition) { return new ModLoot(ailootcondition); } @Override public JsonObject write(ModLoot instance) { return new JsonObject(); } } } Assuming any of this even works in the first place, what would a reliable way to test if the netherite scrap appears in loot chests? Currently using a seed which contains a broken nether portal next to spawn, but the contents are the same across recreating the world.
• Basically a backpack, I would like to know how to store this type of variable inside my Item. What should I use? Item Nbt and json serialize? how?

• 0
• 2
• 0
• 0
• 2
• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...