#Thread
1 messages · Page 1 of 1 (latest)
- Nope. In any random object, in its fixed update. I don't use physics callbacks at all
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
¯_(ツ)_/¯
although good luck i guess
@shadow hinge are you able to call your raycast before the impulse happens?
- There are no raycasts involved; these are debug drawray
well your isTouching logic then
Or do you mean this? https://docs.unity3d.com/ScriptReference/Collider2D.IsTouching.html
- It is called constantly. So should i capture the results for a frame when the jump happens?
- Yes, but for rigidbody
I would
- Pretty unpopular way to detect a ground isn't it
- I'm sorry?
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
- 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
IsTouchingmethod, and a couple more conditions
- This works flawlessly if that's what you're asking. The problem is with
IsTouchingmethod
Is it not possible for you to read the collision before attempting to jump?
void FixedUpdate()
{
bool isGrounded = rb.IsTouching(…);
if(isGrounded) Jump();
}```
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
- 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 theActualJump()happened. It's not the same frame however, actual jump state is only checked during next update
- No. A quick explanation is presented above. To sum this up:
fixed update #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
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
- 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
Do you have rigidbody interpolate/extrapolate on?
- Final frame. Here it finally realises that hey, there was no ground beneath, but grounded transition has been triggered
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
- There are slopes in my game possible, it'd just slide on them until velocity falls back to 0
- Extrapolate broke the entire controller thing, other than that both are equally useless here. Exactly the same sequence of frames and calls
I’m pretty much out of ideas at this point.
My last idea would be to store the timestamp when the jump happens and just have the ground check be evaluated a few milliseconds after
- This smells like spaghetti ngl. But if that's the only option, so be it
Yeah it’s pretty smelly, I was really hoping for interpolate to work
- 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?