Jump to content

Do not allow jumping when falling down


kurhlaa
 Share

Recommended Posts

Hi,

In basic demos people use a variable like allowJump to prevent multiple jumping at the same time. For example, you start a jump - you are in the air, so you can't jump again until you are down. That's OK.

What do I do if I'm on a mesh (allowJump is True), then move from it until falling down - while in the air allowJump is still True, but it must be False. How do I detect this falling down and prevent jumping?

I don't use any physics plugin and for moving I use a camera with a mesh attached to it.

Link to comment
Share on other sites

2 hours ago, Gijs said:

Maybe only allow jumping while on a mesh?

What is the efficient way to check whether camera is on a mesh?

 

2 hours ago, Gijs said:

Otherwise maybe only allow jumping when Δy is 0

by Δy you mean what? The distance from camera to the nearest mesh below it?

 

Which method will work faster and so is preferable?

Link to comment
Share on other sites

4 minutes ago, kurhlaa said:

What is the efficient way to check whether camera is on a mesh?

 

by Δy you mean what? The distance from camera to the nearest mesh below it?

 

Which method will work faster and so is preferable?

I've never worked with collisions, but from the playground there seems to be a onCollide observer, so you can probably use that.

By the Δy I mean keeping track of the previous y position and see how much it has changed, which will be zero when there is no y movement

Link to comment
Share on other sites

7 hours ago, kurhlaa said:

What do I do if I'm on a mesh (allowJump is True), then move from it until falling down

How do you know you are no longer on a mesh and so must fall? If you have some logic that says you have moved off a mesh and so activate a fall then when activating the fall also set allowJump to be false.

Link to comment
Share on other sites

Just now, JohnK said:

How do you know you are no longer on a mesh and so must fall? If you have some logic that says you have moved off a mesh and so activate a fall then when activating the fall also set allowJump to be false.

Like the collisions demo from the playground, where camera.applyGravity = true and meshes.checkCollisions = true

Link to comment
Share on other sites

34 minutes ago, JohnK said:

True but there is no indication that kurlaa is using this method. 

I've mentioned "I don't use any physics plugin and for moving I use a camera with a mesh attached to it.". In general Yes, I use a built-in camera's collisions and movement

Link to comment
Share on other sites

In this case there are problems in wanting to use internal methods (collisions and falling under gravity) to change an external variable (allowJump) this https://www.babylonjs-playground.com/#UTWLUM is  a (poor) attempt to use @Gijs's method of checking for changes in y. One problem is that the gravity and collision methods used seem to change the y of the camera even when moving horizontally. Anyway use the left arrow key to move of the ground and the sphere turns red when falling (but on occasions can do when moving horizontally).

With onCollide I can see how allowJump can be set to true but do not see how to set to false when not in collision. Probably needs a notInCollision observable.

An alternative is http://doc.babylonjs.com/babylon101/intersect_collisions_-_mesh or to use  BABYLON.ActionManager.OnIntersectionEnterTrigger and BABYLON.ActionManager.OnIntersectionExitTrigger in an actionManager

Sorry but cannot be of more help. Interesting issue for 3D platform games as well that would need someone more skilled than me.

Link to comment
Share on other sites

@Pryme8,

22 hours ago, JohnK said:

An alternative is http://doc.babylonjs.com/babylon101/intersect_collisions_-_mesh or to use  BABYLON.ActionManager.OnIntersectionEnterTrigger and BABYLON.ActionManager.OnIntersectionExitTrigger in an actionManager

.. in these methods I have to specify 2 meshes to detect whether one intersects the second. What do I do if the world contains hundreds/thousands of meshes? Every one of them will have this JavaScript trigger? How bad this will be for the performance?

But have found on this forum: "I don't think cameras can use onIntersectionEnterTrigger... because cameras are not a mesh"

Link to comment
Share on other sites

The forum post goes on to say

On 12/3/2016 at 1:16 PM, Wingnut said:

http://www.babylonjs-playground.com/#KNXZF#2

Here, I built a "camera gizmo" mesh, made it invisible, parented it to the camera, and then put the intersect actionManager on the camgizmo.  Seems to be working.

Perhaps others will have comments or better ideas.  Again, welcome, good to have you with us.

So taking this idea plus this SPS playground https://www.babylonjs-playground.com/#10RCC9 and combining shows 2550 solid particles colliding with a sphere imposter around a camera gives https://www.babylonjs-playground.com/#10RCC9#13  (wait for batch of red particles to go then green particles are fired towards the camera turning red when colliding with the camera imposter and being diverted). This is a quick demo cobbled together to show performance without any attempt at any optimisation.

OK  you want a camera that moves and (possibly stationary meshes) but this would probably improve performance. Keep trying and I am sure you will get where you want to be.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...