ID:1763628
 
So I've attempted to make a jumping system inspired by Spirit Age and I've failed horribly. Right now its a mish mash of different attempts at it and kind of works but not really. I've come here to ask for you guys' help at the request of my artist.

How it's supposed to work is: Player jumps > Player moves through a dense turf to the "top" of a "platform" > the player can then fall off or jump off the sides of the "platform".

I've had the idea of using areas and setting some variables for this but it hasn't worked so well.
I've also attempted to implement a sort of "physics loop".

Please keep in mind this is NOT a side-view platformer. It is a typical RPG.

Jump Code:
    Jump()
icon_state = "jump"
//elevation = 2
jumping = 1

vel_y = 32

animate(src, pixel_y = 32, time = 3)

spawn(3)
jumping = 2


Physics Loop:
    PhysicsLoop()
spawn()
while(src)
sleep(0.1)

Gravity()

Gravity()
if(fall == 2)return
if(vel_y > 0 && jumping == 2)
icon_state = "jump2"

vel_y -= 4
pixel_y -= 4

if(vel_y < 0)vel_y = 0
if(pixel_y < 0)pixel_y = 0

if(vel_y == 0)
icon_state = ""
if(running)icon_state = "running"
jumping = 0


Collision detection stuff:

obj
Cross(atom/a)
if(istype(a, /mob/))
if(density == 1)
if(a:jump_up && a:jumping)
return 1

if(a:fall && a:jumping)
a:icon_state = "jump2"
a:fall = 2
return 1

else
return 1

..()


Feel free to ask any questions if I've not been clear.

Thanks.
You can see how it's done in Forum_account's Pixel Movement library, but basically:
/*
(this is the same logic as in 2D sidescrollers, but collision detection isn't done for you)

When you jump, you set vel_z to some positive number.

Every tick:
Add vel_z to your pixel_y (or pixel_z, if using world.map_format == SIDE_MAP or ISOMETRIC_MAP).
Check for collisions:
Check if the lower-height of the player <= the height of the floor (e.g. 0).
Check for dense objects and compare their upper-height with the lower-height of the player.
On collision, set the lower-height of the player to the object's upper-height and set vel_z to 0.
Otherwise, subtract gravity from vel_z.

note:
* The z-axis comes up out of the ground, since +y is north and +x is east.
We represent the z-coordinate using pixel_y or pixel_z.
* Upper-height refers to the z-coordinate of the top of the 3D bounding box.
* Lower-height refers to the bottom of the box.
=> When the bottom of the player is below the top of the box, the player is either:
overlapping the box,
or completely below the box.
If you don't care about being below the box,
you don't have to check for that case, but it's done by
comparing the top of the player with the bottom of the box.
It's pretty basic AABB collision detection.