3D Z-jumping

phillipPbor

Member
I don't know how to make a code for a z jumping's I mean I want to know.
but there is a price for the 3d platformer z jumping in a market place, Rene Couture done the push box, but said I need a money and a gm2 license! I CANT EVEN DO THAT! I need a code from anyone.
I mean You can PM me if you got a code.
 
N

Never Mind

Guest
I wrote this up for you and anyone curious about this subject.
It is not intended as a copy-n-paste (not sure code-request-only posts are even allowed in this Programming Thread?) but rather for you to be able to see a method that I've used before. I'm not claiming it is the best way to go about this sort of thing. I just want to help inspire anyone's imagination that's having trouble getting started.

The idea is that you place block objects in the room (with sprites) that all have their own 3D variables z and zheight.
Adding
zheight to z tells you where the top of the potential 3D cube would be. z is the base.


It assumes you use x and y like a top down (from directly above) game.
However, if you change the way I use collision to detect above/below stacks of blocks, then you could adapt it to whatever perspective.

obj_player:
---------------------------------------------------------------------------------------------------
Create Event:
z = 0;
gravAcc = 0.3;
gravSpeed = 0;
blocksBelowList = ds_list_create();
---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------
Game End / Room End Events:
ds_list_destroy( blocksBelowList );
---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------
Begin Step Event:
//reset since we've moved

ds_list_clear( blocksBelowList );
---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------
Collision with obj_3dBlock Event:
//find potential collisions in the direction z is moving

if( gravSpeed > 0 and other.z+other.zheight < z){
ds_list_add( blocksBelowList, self.id );
}
if( gravSpeed < 0 and other.z > z){
ds_list_add( blocksBelowList, self.id );
}
---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------
Step End Event:

//find nearest z target

var zClosest = 99999;
for( i=0; i<ds_list_size( blocksBelowList ); i++; ){
var iBlock = ds_list_find_value( blocksBelowList, i );
if( gravSpeed > 0){
if( abs( z - (iBlock.z+iBlock.zheight) ) < zClosest ){
zClosest = (iBlock.z+iBlock.zheight);
}
}else{
if( abs( z - iBlock.z) < zClosest ){
zClosest = iBlock.z;
}
}
}

//accelerate
gravSpeed += gravAcc;

//if collision zero
if( gravSpeed > 0){
if( z + gravSpeed > zClosest){
z = zClosest;
gravSpeed = 0;
}
}else{
if( z + gravSpeed < zClosest){
z = zClosest;
gravSpeed = 0;
}
}

//apply
z -= gravSpeed;

---------------------------------------------------------------------------------------------------

I'm not trying to deter your post!
I'm honestly curious about whether purely code requesting posts are allowed anywhere besides say Off Topic and Community Chat
 
Last edited by a moderator:
Top