Jump to content

moveWithCollisions


iiceman
 Share

Recommended Posts

Hi again :)

 

I had quite some fun playing around with moveWithCollisions based on an example from dad72 (this one: http://www.castorengine.com/babylon/moveCharacter/). I added some kind of mouse/click control. so if you click somewhere the cube moves there. Now I want ramps to walk up on stuff. Took me a while, probably bad programming, anyways... works. Now jumping down from the ramp works, too, as long as you land on the ground or the big cube. But if you try to jump from the big ramp onto the smaller ramp it get stuck somehow. To illustrate it I added lines that show a raycast from the green cube downwards.

 

Please have a look at this: http://p215008.mittwaldserver.info/moveWithCollisions/ (moving too much slows it down pretty bad because of all the lines.. I know, bad programming, but ignore that for now and consider reloading the scene if it gets too slow :P )

 

Questions:

1) on the ramp the lines for the raycast are much shorter... I don't really understand why... why?

2) jumping from the big to the small ramp you see that the green box doesn't move as expected...what am I seeing here? It's not the bounding box of the ramp, is it? I assume it has something to do with the rotation?

3) how do I make it work? (I thought I needed a third... so I put that here)

 

As I said, it's big fun again and I think it looks pretty cool. I like all those lines even if they ruin the performance... well, it's past 4am here and I might be a bit tired so forgive me if this post is overwhelmingly full of nonsense.

 

Can't wait for your input guys! ... but have too sleep now :D

Link to comment
Share on other sites

Hi i-man!

    I have no solutions but I made a playground of it... http://playground.babylonjs.com/#1NQTNE .  That makes it easy for folks to experiment and/or grab a home zip, and play along.  I also turned-off shadows, temporarily.

Yeah, you have a fun world of ramps and jumps started here.  WASD to drive around, but I don't think A/D are coded-up, yet.  It's 3:30 AM here, and I just barely got the playground version operational.  There is some drool on my keyboard, so I assume I am tired.  :)

These picking rays are fun.  I know very little about them, but iiceman has found an interesting use, here.  It seems that they NEARLY allow us to watch the collision ellipse interact with environment... live, in real time.  Handy!  Interesting!  I'm going to study this... tomorrow.  :) 

Besides, the experts on moveWithCollision will be waking soon.  It's best that I'm not in their way.  :)

Link to comment
Share on other sites

Thanks for putting that into a playground, I tried to just copy paste it but I got some errors so I thought I let you guys have a look at it just like that. I saw you modified the GRAVITY constant the I set so the playground might behave a little bit different but the problem is still very obvious to see.

 

And yeah, A/d for the controls is not implemented yet. Not sure how to do that, have to think about it a bit more since I just copied from dad72 :P

 

Anybody else an idea whats going here? It kinda looks like there is another big bounding box around the ramp that prevents the jumping on it but I don't understand it at all, so I am grateful for any hint here!

Link to comment
Share on other sites

I made another...  stripped it down some more, moved to a side view with the green player all lined up on the large ramp.  I also started out with green player at 10 units +Y (in the air).  So, one would think, that holding the W key... would make the green player immediately fall to the ground.  It doesn't.  In fact, scene gravity seems to be failing, but i could easily have something wrong.  Anyway, just hold W and off you go over the ramps... gravity free for some reason.  (Folks might have to click on the canvas before using the W key)

hmmm.  I actually made it worse.  :)  http://playground.babylonjs.com/#1NQTNE#1

That green box should fall upon seeing a W keypress, I think.  *scratch scratch*  Puzzling.

Link to comment
Share on other sites

Ok, thanks for showing me where I screwed that up.

Another version:  http://playground.babylonjs.com/#1NQTNE#5

I also turned-on basic right and left movement... but I don't know if I did it correctly.  It works, at least while in side-view like we are.  Left/right might need adjusting... when you return to your original following view.

In this version, I added a fifth condition at line 132.  In effect, it means when no keys are pressed, STILL try to move downward based upon GRAVITY setting... which is also used in scene.gravity.y.

The rays are still being drawn "short" after dropping off the large ramp, but at least the playerMesh is falling all the way to the base of the small ramp.  I'm still studying it. 

Try this for fun.  Immediately upon leaving the large ramp (before completing the fall), hold the S key to reverse.  As soon as we reverse far enough to clear the small ramp, the rays start reaching the ground again.  Or you can use A/D to go sideways until you are no longer above small ramp... same affect.

Not sure why the rays don't want to reach down to the surface of the small ramp.  *scratch scratch* 

Link to comment
Share on other sites

I tried to play with the code a bit. I have no solution thou :-) Needs further debugging. I just wanted to point out a few things, maybe they can help with finding a solution.

 

  • As the error appears with both mouse clicks and keyboard moves, i doubt there is something wrong with the animate function.
  • I find it odd that the box always "floats" in the air and is not constantly stuck to the ground (when above the ground). You can also see how the red lines minimize once you get to a ramp. That's the strangest thing i could find in this scene (apart from the fact that when jumping from the upper ramp you don't get to the lower one :-) ). 
  • The mouse up function should actually check if the scene pick has a hit, otherwise you get an error, since you are cloning a non-existing point.
Link to comment
Share on other sites

Hey again, thanks for the help guys!

@Raan, I fixed the mouse pick/clone on null thing. I am not sure either why the box is floating... that seems to has something to do with the ellipsoid and its offset..nut sure... you can compensate it by choosing appropriate values for it but it find really response as I excepted it to so I ignored it for the time beeing.

@Wingy, I had that, too, where you add gravity even if it doesn't move. The result is that the box slides down the ramp if you don't move. I don't really want that... not sure anyways if that's the best way to use moveWithCollsions + gravity, but since nobody suggested something way better yet I think it might be okay.

I played a bit more and ended up with this one http://playground.babylonjs.com/#1NQTNE#9

What I've learned:

I had the idea that it might not be a problem with the animation, the raycast itself or the rotation, but maybe something else. So I tried to it without scaling ... et voila (did I say that right? :D ) it worked aaalloooot better, you can check it out in the playground above, it's best seen if you first walk on the small ramp, the one with scaling. Just walk up a bit by clicking you way there (I disabled keyboard input for testing things). And when you are half way on the ramp just walk it down again. The cube starts floating just the same as when we tried to jump on the ramp. Now do the same with the unscaled cube.. see? Everything seems to work fine!

So the problem is the scaling.. or better the raycasting in combination with the scaling? I guess something goes wrong when computing the point where the ray hits on the scaled box. Is this a bug? And if it is, do I get a cookie for finding it!?? (@delthakosh :D )

 

Yeah... that's all I know so far... don'no how to fix that... maybe I could compensate the scaling myself somehow by using the bu and bv values of meshFound if I apply the scaling to them that I applied to the box... somehow? I really don't know, that all doesn't seem right. I can't really use it without the scaling I guess... maybe if I do my ramps in blender... but that would be kinda weird for something that simple, wouldn't it?

Soooo... still waiting for you veterans to help me out here :P

Motivation:

Imagine all the possibilities! Point and Click Adventure, Real Time Strategy games, RPGs with keyboard and mouse control.... and all in a cute little world, full with boxes and ramps and gravity and collisions and stuff! Would be awesome, eh? Yes, right, it would be! And you can make it happen by solving this little problem here ;)

Link to comment
Share on other sites

Hmm... kind of.. well almost... it still acts a bit weird sometimes. And it only works if the gravity is -5. What exactly did you change? I don't really see a difference right now. I don't really have time to check the details right now...

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...