playMaker

Author Topic: Doodle Jump like smooth movement  (Read 425 times)

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Doodle Jump like smooth movement
« on: October 13, 2018, 05:08:01 AM »
I am attempting to make something similar to Doodle Jump but the player character and camera movement is quite jittery.
I unfortunately have no idea how this should be done the best way.
Please share any thought or own experience I should try.

I have tried many different camera follow actions but none worked smoothly as in Doodle Jump.

The best so far I could do is move the player (kinematic rigidbody) with RigidBody2dMovePosition.
Setting it's position to an animated float curve value, simulating the jump height change.
And the camera is following this object.
Please see attached image for details of the current setup.

Thank you in advance for any ideas on how such a thing should be done to have it move smoothly.

br,
szomaza

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #1 on: October 13, 2018, 05:37:57 AM »
Also what about collision detection with platforms the player character jumps on?
It can NEVER happen that the character falls through a platform.

Is it good to rely on collision enter 2d events to detect falling on platforms or can/should it be more reliably faked?

I read something about 2d raycasts.
How does that work?
Do you have to cast a ray down from the character, then store that position and check until the character goes under it and then jump again?

Thanks,
szomaza


Thore

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #2 on: October 13, 2018, 11:32:03 AM »
Hi,

I also make a platformer, and some aspects can be more inticate than they seem ;)

I start simple. They then get refined considerably, to get to the nice juice. I use a rigidbody2D, and the actions to move set velocity2D every frame. The move FSM has one ini state (to initialize, fetch stats etc.) and only two states, one for moving left and one for moving right. Search for my actions here in the forum, I combined the core actions into one. On top of each state, I flip the sprites. Underneath, I get the axis each frame, and set velocity 2D each frame (and more for animations, particles, sound)

Jump works similar. The basic version has few states: listen to button down, next state apply velocity 2D upwards. System global transition “On Collision Enter”, on the start state.

Next, for camera, use Cinemachine (free package of Unity). See some tutorials for it, this makes the camera move smoothly and has plenty to tweak how to move. The settings totally depend on your game, but see Brackeys example below. To pass platforms upwards, Blackthornprod (other video below) uses platform effectors 2D on the platforms.

I recommend also Unity or coding tutorials. While they are eventually about coding, they use the very same concepts Playmaker also uses (or rather, vice versa). Checkout Brackeys and Blackthornprod on YouTube (generally), but here are two you’ll find useful (you can of course also ask :))

ONE WAY COLLISION PLATFORMS - EASY UNITY TUTORIAL
https://www.youtube.com/watch?v=M_kg7yjuhNg

2D Camera in Unity (Cinemachine Tutorial)
https://www.youtube.com/watch?v=2jTY11Am0Ig
« Last Edit: October 13, 2018, 11:46:55 AM by Thore »

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #3 on: October 14, 2018, 12:58:57 AM »
Hi Thore,

Thank you very much!
Great ideas and lots of stuff to take in. I'll be occupied with those for a while.

I do have one question right away about using a rigidbody2d as the player and moving that around. I have that setup now (as the latest attempt to make it work) and the problem with it is when "teleporting" from one screen side to the other.

(In Doodle Jump the character can move out on one side of the screen and enter on the other side: teleporting from one edge of the screen to the other.)

The problem with this is that the RigidBody2dMovePosition
https://docs.unity3d.com/ScriptReference/Rigidbody2D.MovePosition.html
as it rapidly moves the character from one side to the other, it affects dynamic objects in the center of the screen.
If there is a tower made out of dynamic blocks, it will just instantly push any block hit, all the way to .... Siberia (...I guess, as they just disappear when the character is teleported across them)

This is the reason, I am thinking to go back to not using a rigidbody2d as the player, but fake everything: have the player character be just a regular object moved by it's transform, use raycasts to detect platforms.
Of course then I'll have problems with player interacting with dynamic physics objects: pushing them around.

I would appreciate any encouragement, insight on why to go one way and stick with that setup for such player character.

Thanks,
szomaza
« Last Edit: October 14, 2018, 01:17:04 AM by szomaza »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #4 on: October 14, 2018, 02:48:18 AM »
Hi.
If your 'teleport' is instant use set position instead.
If you want to move it over time and don't want it to hit stuff you could disable the collider temporary.

I did some research and you can also use ignore layer collission in c#
There is no action yet for PlayMaker but i will try to make one today.

If you need this and i did not reply, please bump this thread

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #5 on: October 14, 2018, 02:52:57 AM »
You could also use set layer to change the layer on the player during teleportation

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #6 on: October 14, 2018, 04:33:49 AM »
Thank you djaydino, great ideas!
The set layer for the duration of the teleport sounds straightforward and the easiest to try for me right now but I'll try the set position also.
I have been moving the kinematic rigidbody2d character with set position before but then got afraid of that after reading here:

https://docs.unity3d.com/Manual/class-Rigidbody2D.html

"Kinematic Rigidbody 2D is designed to be repositioned explicitly via Rigidbody2D.MovePosition or Rigidbody2D.MoveRotation."

After this I switched to Rigidbody2D.MovePosition hoping that this way it will detect the platform Enter2DCollider more reliably and might never fall through a platform.
Which would be a disaster in such a game.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #7 on: October 14, 2018, 05:11:39 AM »
Hi.
In the attachment below you can find the Ignore Layer Collision

this works by index.

there is also a physics ignore Collision action on the ecosystem but this works with objects, so its kinda limited :)

Let me know if it works :)

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #8 on: October 15, 2018, 10:10:08 AM »
Hi djaydino,

I just tried your above 2 ideas and they worked perfectly to solved my problem:

1. using the SetLayer action to set it for the player to a non-colliding layer for the time it is teleported to the other side.
2. EnableCollider2D also works the same way.

Both needed a 0.1 sec. wait before turning them back on after the teleport. One frame wait was not enough and it also occasionally glitched (teleporting the player back and forth) with only 2 frame wait.

I also tried your action but it does not seem to work. I am not sure what is the problem. It does not seem to be doing anything.
I set it to ignore the collision of my player layer and the dynamic blocks but still they collide.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #9 on: October 15, 2018, 01:43:08 PM »
Hi.
Oops i forgot to assign the bool condition.

I updated the action, it should work now.

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #10 on: October 20, 2018, 10:17:04 AM »
Hmmm, I still can't get it to do anything. 
I simply set it to ignore player and platform collisions to try it but still he keeps bouncing on the platform.
What should I try to find the/my problem?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #11 on: October 20, 2018, 04:01:03 PM »
Hi.
Can you try to set them manually

Go to Edit/Project Settings/Physics

in the inspector you will see the collision matrix.

on the top right there is a little lock image, you can lock the current inspector screen.

Then play the game and look to the matrix if things get changed.

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #12 on: October 24, 2018, 10:08:31 AM »
LOL, sorry it works perfectly...  ,but for 3D physics.

I just realised the name of it is:
PhysicsIgnoreLayerCollision
and not
Physics2DIgnoreLayerCollision
:-)

I am making a 2D platformer and I did check the collision matrix to make sure, but only the 2D matrix.

Anyway I am using the SetLayer action to set the Player to a non-colliding layer for the time it is being teleported and that seems to be working nicely.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Doodle Jump like smooth movement
« Reply #13 on: October 24, 2018, 10:30:42 AM »
Hi,
Ah yes..

I made one for 2d now also (see attachment below)

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: Doodle Jump like smooth movement
« Reply #14 on: October 27, 2018, 12:40:56 AM »
Thank you very much!

Now this seems to be an equivalently good solution to the problem but in such cases:

How do I know which one is better?
Uses less resources?
Or should something else be considered to decide which one to use?

1. changing the layer of the object to a non-colliding layer,
or
2. using IgnoreLayerCollision2D to achieve the same.