DoodleJump type gameplay, Unity 3D

by on under Code snippets
1 minute read

Some people had questioned me how to jump through a platform, like in doodlejump.
The basic idea it’s that you change the layer of the player when he jumps and change it back when he has negative Y velocity. Demo The code is pretty basic:

float jumpForce = 1000f;
void Update(){
	if(Input.GetKeyDown (KeyCode.UpArrow)){
		rigidbody2D.AddForce (new Vector2(0f, jumpForce));
		gameObject.layer = 9;//PlayerInAir Layer
	}
	if(rigidbody2D.velocity.y < 0){
		gameObject.layer = 8;//Player layer
	}
}

After that, go to Edit -> Project Settings -> Physics 2D and uncheck the collision between PlayerInAir and Ground layers. LayerSettings

Unity 3D, code snippet, doodle jump, platform
comments powered by Disqus