Page 1 of 1

Mod idea - Autojump

PostPosted: Sun Oct 19, 2014 07:57
by Rochambeau
Hi,

i would like to create a mod that, when the player walks near an one block high obstacle, the player automatically jumps. (IIRC this is the common behaviour in MC PE)

The problem is I don't know how to start at all. Is there some code that I could "borrow" from a similar mod?
I guess the mobs mods might have something useful as the animals can walk up hills, but I haven't found the right lines yet.

Re: Mod idea - Autojump

PostPosted: Sun Oct 19, 2014 09:51
by 4aiman
I wouldn't recommend doing this from lua, but...
You can:
- invoke player:get_yaw()
- read player:get_player_controls().up
- and if there's a node at player:getpos() + vector, received from yaw and the second one is TRUE, then jump.

The only problem is that you can't invoke a jump.
So, I'd not recommend you to continue this way, but...
You can:
- create an entity at player:getpos()
- attach a player to it
- make it jump (see mobs by PilzAdam)
- detach the player and remove the entity.

But. as I've said... look at the android controls. Maybe an autojump option for PC edition won't be so horrible to prevent it from merging.

Regards!

Re: Mod idea - Autojump

PostPosted: Sun Oct 19, 2014 19:45
by napodan
I like the idea for android build : it's hard to point, push up and jump without dropping your phone.

For simple mobs, as I understand, when the mob is moving but its velocity is inferior than a certain value (0.5 in normal walk and 1.5 in following walk), you just change the y velocity (which is often null) by 5 or 6. The mob will jump.

Re: Mod idea - Autojump

PostPosted: Wed Oct 22, 2014 20:24
by Calinou
Change the step height in the source code. This way, you have something fully client-side, usable on any server, without lag.

localplayer.cpp line 194:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
float player_stepheight = touching_ground ? (BS*0.6) : (BS*0.2)


Change BS*0.6 to BS*1.1 then recompile.

I believe this step height could automatically be used on Android builds, it seems fair considering controls are harder to use there.

camera.cpp line 275:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
      f32 t = exp(-23*frametime);


Change -23 to -7 for more smoothing. -10 is a good value with the default step height, but here we are stepping up larger heights.

Re: Mod idea - Autojump

PostPosted: Fri Oct 24, 2014 05:26
by Ascent
Calinou wrote:Change the step height in the source code. This way, you have something fully client-side, usable on any server, without lag.

That's really useful. I'm building my client with this from now on. Thanks, Calinou!

Re: Mod idea - Autojump

PostPosted: Tue Oct 28, 2014 02:38
by Sokomine
Calinou wrote:Change the step height in the source code.

Sounds like a very good idea, especially regarding the android client. It would be great if it could be made configurable.
The drawback is that an increased step height will make braking at the end of roads in fast move more difficult.