Topic category: Help with Minecraft modding (Java Edition)
In the latest official April Fools' update, there's an item called the 'Lashing Potato' that works as a grappling hook. When the player right clicks, it shoots out a projectile (not affected by gravity), and if that projectile hits a block, it'll start pulling the player towards the projectile until the player right clicks again to let go.
This visually also has a texture that stretches in a straight line from the player to the projectile. Here's an example of how that looks; https://imgur.com/a/snaJAUh
Now, I have no clue if any of this is possible in MCreator at all; but would anything like this be possible? Preferably including the rope/vine that visually connects to both the player and the projectile/hook. Any help is appreciated.
It's possible! Just, from personal experience, very annoying to do properly!
The grappling hook is essentially just a spring, which means it works on spring physics. The game saves the position the hook is attatched to, and then adjusts the player's position based on the tension between the two points, which increases based on distance. Which sounds simple, but involves a fair bit of math. But the basic idea is that you need to save a position as player-lifetime number variables, and then have a logic variable to determine whether the player is attatched to something. Then every update tick, you adjust the player's velocity accordingly.
The tricky part is actually the visual effect. I couldn't figure out how to do an elongated texture like the potato, or the guardian beam, but I was able to make chain links and a hook; I essentially just made them non-collidable entities that constantly set their position to various points along the vector between the player and the attatchment point.
This obviously won't work like an actual rope, and won't take block collisions into account, but should otherwise work pretty effectively. My method also doesn't use an actual projectile, it just instantly attatches to the location you're targeting. (It's possible to use a real projectile, I just found this method to be more satisfying.)
Here's a link to some of the procedures I used, if you're interested. Best of luck!
Can you make a video or something to show how to do this, if you do it would get a lot of views because a lot of people want to know how to do this, and i still don't quite understand how to do it.
Maybe at some point, I've never really thought about video tutorials. I figure I'll need to make some trailers for my modpack eventually, but in the meantime I don't know a thing about video editing.
It's tricky because it's not just enabling something or using a preexisting system, there isn't anything in the game that does this, so the physics have to be coded from scratch. Basically, you need a system that draws the player towards a point when they get beyond a certain range, and then an item that determines where that point is.
The math is just kind of difficult to explain if you're not familiar with it; hopefully the procedures help. There's some decent khan academy stuff on 2d spring physics, and it's pretty much the same with an x/y/z axis.