#Thread

1 messages · Page 1 of 1 (latest)

lusty comet
#

oh yea

#

ok

#

So just use void OnCollisionEnter2D(Collision2D other)

shadow hinge
#
  • Nope. In any random object, in its fixed update. I don't use physics callbacks at all
lusty comet
#

oke then thats gonna be harder for me because thats what i do all the time sorry

#

so im really sorry but this is the only way i know it works so bye i guess

shadow hinge
#

¯_(ツ)_/¯

lusty comet
#

although good luck i guess

low fog
#

@shadow hinge are you able to call your raycast before the impulse happens?

shadow hinge
#
  • There are no raycasts involved; these are debug drawray
shadow hinge
#
  • It is called constantly. So should i capture the results for a frame when the jump happens?
shadow hinge
shadow hinge
low fog
#

I would capture the results before the code that moves the object

#

Most types of physics controllers would check whether the object is touching the ground before applying the jump

shadow hinge
#
  • In my one, there's no direct jump after the input is gain. It just gets an external message "hey you need to jump if you can" and there's no grounded demand on this
#
  • The condition to perform a jump is complex, and it involves jump input, essentially a bool, grounded status, essentially an IsTouching method, and a couple more conditions
#
  • This works flawlessly if that's what you're asking. The problem is with IsTouching method
low fog
#

Maybe im misinterpreted this. What it sounds like to me is that you are trying to add a system where the player is able to queue up a jump midair

shadow hinge
# low fog Is it not possible for you to read the collision before attempting to jump? ```c...
  • I do this in every fixed update. I can into deep details but it's going to take long, so simple representation would be
bool _jumpInput;

void Jump () => _jumpInput = true;

FixedUpdate()
{
  if (_jumpInput && IsTouching(GroundFilter) && OthersConditions) ActualJump();

  // during actual jump (it's a state)
  if (IsTouching(GroundFilter)) EnterGroundedState();
}
  • And the problem is, EnterGroundState() is called immediately after the ActualJump() happened. It's not the same frame however, actual jump state is only checked during next update
shadow hinge
# low fog Maybe im misinterpreted this. What it sounds like to me is that you are trying t...
  • No. A quick explanation is presented above. To sum this up:

fixed update #1

  1. State is switched to actual jump because input is gain and the body is grounded. Impulse is added to the body

fixed update #2
2. Body is not touching the ground anymore, but. It still thinks that it's grounded, despite the fact that it's not, thus it quits the jump state straight away

fixed update #3
3. Grounded state is entered. IsTouching never returned false, as if body didn't get any impulse

low fog
#

ok I think I see where I was confused. I thought the issue was that you want isGrounded to be true but you want it to be false

shadow hinge
#
  • Well, you can put it this way. It's just not exactly up-to-date, delayed by 1 or 2 frames
#
  • Screenshots of every frame:
#
  • Jump happened
#
  • Next frame. The body is still grounded, according to its outputs. All checks and draws are handled in fixed update
low fog
#

Do you have rigidbody interpolate/extrapolate on?

shadow hinge
#
  • Final frame. Here it finally realises that hey, there was no ground beneath, but grounded transition has been triggered
shadow hinge
low fog
# shadow hinge

You could try messing with it. It has to do with the engine predicting where the character will be.

#

Also since you are using a rigidbody, it should be fine to check whether the velocity for y is negative/close to 0 before switching to ground check

shadow hinge
#
  • There are slopes in my game possible, it'd just slide on them until velocity falls back to 0
shadow hinge
low fog
shadow hinge
#
  • This smells like spaghetti ngl. But if that's the only option, so be it
low fog
#

Yeah it’s pretty smelly, I was really hoping for interpolate to work

shadow hinge
#
  • Or maybe. There's going to be a separate condition that sets to false by default and is reset by the jump state as soon as grounded status turns to false. And then include this condition into a transition condition
#
  • However i really don't like this external workarounds. This has to do something with the physics itself. It's okay to delay the status update to a next fixed update, but for 2 of them?