playMaker

Author Topic: Precise platformer collision detection  (Read 1446 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Precise platformer collision detection
« on: June 14, 2021, 10:31:34 AM »
Hello,

i'm trying to figure out controls for a 2d platformer. I'm using translate movement on fixedupdate, raycasts every frame for collision detection and have locked the framerate to 60 fps yet i don't get precise results.

I am using 3 raycasts per direction. However, they are from the center of the character, might work better if they are from the edges and are shorter, though i played around with corgi engine and it uses 4 rays per direction from center of the character and it works flawlessly. I don"t know if they use translate or velocity for movement.

For example, when hitting wals, player always stop at a bit different position:







Any ideas on how to make it precise at all times?
« Last Edit: June 20, 2021, 03:10:46 PM by Fat Pug Studio »
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Precise platformer collision detection
« Reply #1 on: June 14, 2021, 02:45:49 PM »
Hmmm well, i just read that when you move the object by manipulating transform (by translating) it syncchrobises with physics system and small inconsistencies occur. I'll try using velocity or rigidbody.moveposition.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Precise platformer collision detection
« Reply #2 on: June 14, 2021, 04:31:49 PM »
Hi.
With velocity it best to test in builds and if in editor in full screen not showing other windows (also not on your other monitors if you have)
Playmaker can affect preciseness as well as other windows (animator for example)
in editor when you use timescale (i use it for animation testing) the velocity is also not acurate when scale is for example 0.1 (slowmotion)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Precise platformer collision detection
« Reply #3 on: June 15, 2021, 12:12:15 PM »
Unfortunately, it's making issues in both fullscreen editor and in build. I also put 8 raycasts per direction, but to no avail. I'll try to hide it with pixel perfect camera if i can't nail it.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Precise platformer collision detection
« Reply #4 on: June 16, 2021, 06:31:47 AM »
hi.
in our game we have a separate collider for floors/Walls collision maybe that can help

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Precise platformer collision detection
« Reply #5 on: June 16, 2021, 09:21:12 AM »
I just tested trigger collisions, they work on spot every time, so i'll be using trigger colliders for precise movement and raycasting in combination for detecting whether the player is grounded, jumping and so on for double jumps, wall slides and other stuff.
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Precise platformer collision detection
« Reply #6 on: June 20, 2021, 04:05:33 PM »
Hah, back to unsolved. Trigger collider works good if the speed of the character is not high. I tried lowering the fixed update timestep to 0,016 but the trigger reacts too late when jumping.

However, i'm using tweening for jumping, i'll try good old translate or maybe physics since all the examples i see use force for jumps, maybe because of sync with physics.

Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Precise platformer collision detection
« Reply #7 on: June 20, 2021, 05:11:53 PM »
HI.
I had force also before but i changed to velocity with a tween float action. (only tweening Y)

Why you want to lower the timestep (just wondering)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Precise platformer collision detection
« Reply #8 on: June 21, 2021, 04:56:13 AM »
I'm also using the velocity and tweening float for jumps. Fixedupdate uses fixed timestep, if it's set to default 0.02 that's updating physics calculations 50 times per second on 60 fps, so i believe the proper way it to set it to 0,016 so the update timestep matches the fixedupdate timestep (at least in theory).

Anyway, when i use trigger 2d it's not precise. I can fix it by making a bigger collider, but jump speed is tweening to 0, so what works when hitting a ceiling 1 unit away does not work when hitting a ceiling that's 3 units away when the player is already slower.

Also, raycast2d action uses update, i don't know if it would be worth a try changing it to work on fixedupdate.

Whatever i try, trigger2d with colliders or raycast2d, i don't get consistent and precise results :/
Available for Playmaker work