May 5, 2018 at 11:02 pm #14578
Very cool! Landing on its own is quite fun, how about…
May 6, 2018 at 2:44 pm #14580
- A landing zone target(s).
- Ability to crash the landing if you’re going too fast or land too far from target.
- A velocity readout/indicator, perhaps turns red if you’re going too fast?
Yeah, landing pads and crashing are on the to-do list, probably flying through hoops and stealing the orb, plus fuel/fuel collection.
Still fighting my camera, not got it any better than in the last update, but it’s not too bad, so will live with it for now.May 13, 2018 at 1:03 am #14616
Just a minor update after finally figuring out collision groups — smoke now collides with terrain, without affecting the rocket (which got knocked off course by the smoke objects last time I added this). Just a nice visual effect, but landing pads should be easy now too!
EDIT: Ignore below, seem to recall there was a fix for this, not updated yet! Just means the web version will fail for now…
However, it seems to fail on Emscripten here:
*Cut*May 16, 2018 at 10:11 pm #14645
Fixed web version with ground-colliding smoke particles. (Note that thanks to collision masks/groups they don’t collide with and affect the ship as they once did.)
As an ‘also’ ahead of the main question: would it be possible to get shadows for alpha’d entities? Even if it uses the non-alpha’d entity to generate the shadow, and just alphas the resulting shadow, that would be cool. (No idea how shadows work.)
EDIT: IGNORE, major “Duh” on this part below — Collide (body:RigidBody) refers to the OTHER body! Works fine using the correct body! Still need to figure out correct velocities for my triangles, but basically good.
Anyway, I’m trying to get the velocity of a body at the time of collision, but it always seems to be 0, 0, 0. Any idea how to get this? Wondering if it’s stored in some separate collision info?
I’ve even tried storing the body’s velocity just before calling scene.Update but the result is still 0 when the Collided callback runs…
This is a very messy WIP, but I’ve highlighted the relevant points with ' CHECK_ME!
My triangles need work, as I have to use boxes for their bodies… might amend the resulting triangles to rects to work around this.
In reality, it needs a proper model and a chunkier ‘split-parts’ model to do it properly, as I’m skipping many tris when splitting the model, and it’s still slow in webgl.
If I can get collision velocities, though, it should look pretty cool in the meantime.Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338[crayon-5bc8ecd2500a6528466265 inline="true" ]#Import "<std>"#Import "<mojo3d>"'#Import "assets/glass.wav" ' CC0 by ngruber, https://freesound.org/people/ngruber/sounds/204777/Using std..Using mojo..Using mojo3d..' ----------------------------------------' Application name...' ----------------------------------------Global AppName:String = "Shatter!"' TODO: Return array of tri models??' Single tri...' Collision typesConst COLL_NOTHING:Short = 0Const COLL_GROUND:Short = 1Const COLL_TRI:Short = 2Const COLL_BALL:Short = 4' Collision groupsConst GROUND_COLLIDES_WITH:Short = COLL_TRI | COLL_BALLConst TRI_COLLIDES_WITH:Short = COLL_GROUND ' NOT with other tris! Too slow!Const BALL_COLLIDES_WITH:Short = COLL_GROUND' Maybe return as rects so Boxf collisions can be used?Function ModelFromTriangle:Model (in_model:Model, index:UInt)Local mesh:Mesh = in_model.MeshLocal tri_model:Model = New Modeltri_model.Material = in_model.Material' New PbrMaterial (Color.Red)' Cast <PbrMaterial> (tri_model.Material).ColorFactor = Color.Orangetri_model.Material.CullMode = CullMode.NoneAssert (index + 2 < mesh.NumIndices , "Index too high") ' Think that's right...Local indices:UInt  = mesh.GetIndices ()Local tri_verts:Vertex3f  = New Vertex3f ' mesh-local co-ords...tri_verts  = mesh.GetVertex (indices [index + 0])tri_verts  = mesh.GetVertex (indices [index + 1])tri_verts  = mesh.GetVertex (indices [index + 2])Local tri_indices:UInt  = New UInt tri_indices  = 0tri_indices  = 1tri_indices  = 2Local tri_mesh:Mesh = New Mesh (tri_verts, tri_indices)tri_mesh.UpdateNormals ()tri_mesh.UpdateTangents ()tri_model.Mesh = tri_meshtri_model.Parent = in_modelReturn tri_modelEndClass PhysicsTriField model:ModelField body:RigidBodyField collider:BoxColliderEndClass Game Extends WindowConst SHIFT_BOOST:Float = 5.0Field camera_boost:Float = 1.0' Basic 3D scene requirements...Field scene:SceneField camera:CameraField light:Light' Test ball...Field ball:ModelField sound:SoundField b_coll:SphereColliderField b_body:RigidBodyField exploded:BoolField run_physics:BoolField lastvel:Vec3fMethod New (title:String, width:Int, height:Int, flags:WindowFlags)Super.New (title, width, height, flags)sound = Sound.Load ("asset::glass.wav")scene = Scene.GetCurrent () ' Important!camera = New Camera' Camera settings...camera.Near = 0.1' Camera position...camera.Move (0, 21.5, -2.5) ' Ground is 5 high'camera.Viewport = Window.Rectlight = New Lightlight.Move (-100, 100, -100)Local size:Float = 4.0ball = Model.CreateSphere (size * 0.5, 36, 36, New PbrMaterial (Color.Aluminum))ball.Move (0, 20, 15)ball.Alpha = 0.3Cast <PbrMaterial> (ball.Material).MetalnessFactor = 1.0b_coll = ball.AddComponent <SphereCollider> ()b_body = ball.AddComponent <RigidBody> ()b_coll.Radius = size * 0.5b_body.CollisionMask = COLL_BALLb_body.CollisionGroup = BALL_COLLIDES_WITH' TODO: Copy velocity from main ball...'b_body.ApplyImpulse (New Vec3f (0.0, 0, 5))ball.Collided += Lambda (body:RigidBody) ' CHECK_MEIf Not exploded Print body.LinearVelocity Else Return ' 0,0,0 at collisionLocal SKIPPER:Int = 5 ' Skip every SKIPPER triangles for speedLocal dir:Vec3f = New Vec3f (0, 0, 5)Local thickener:Boxf = New Boxf (0.0, -1.0, 0.0, 0.0, 1.0, 0.0)For Local loop:UInt = 0 Until ball.Mesh.NumIndices Step 3 * SKIPPERLocal ptri:PhysicsTri = New PhysicsTriptri.model = ModelFromTriangle (ball, loop)ptri.model.Parent = Nullptri.collider = ptri.model.AddComponent <BoxCollider> ()ptri.collider.Box = ptri.model.Mesh.Bounds' + thickener'Print ptri.model.Mesh.Boundsptri.body = ptri.model.AddComponent <RigidBody> ()ptri.body.Mass = 1.0ptri.body.Restitution = 0.25ptri.body.Friction = 1.0ptri.body.AngularDamping = 1.0ptri.body.CollisionMask = COLL_TRIptri.body.CollisionGroup = TRI_COLLIDES_WITH' ptri.body.ApplyTorqueImpulse (New Vec3f (0.001, 0.001, 0.001)) ' All disappear??ptri.model.Rotate (Rnd (360), Rnd (360), Rnd (360))' CHECK_ME' Print lastvel' ptri.body.ApplyImpulse (ptri.model.Basis * dir) ' Exaggerate angular velptri.body.ApplyImpulse (ptri.model.Basis * (lastvel * Rnd (10.0))) ' Exaggerate angular vel' ptri.body.ApplyImpulse (ptri.model.Basis * (body.AngularVelocity * Rnd (10.0))) ' Exaggerate angular velNextsound.Play ()exploded = True'b_body = NullEndLocal g_box:Boxf = New Boxf (-100, -5, -100, 100, 5, 100)Local ground:Model = Model.CreateBox (g_box, 4, 4, 4, New PbrMaterial (Color.Green * 0.5))light.PointAt (ground)Local g_coll:BoxCollider = ground.AddComponent <BoxCollider> ()g_coll.Box = g_boxLocal g_body:RigidBody = ground.AddComponent <RigidBody> ()g_body.Mass = 0.0g_body.CollisionMask = COLL_GROUNDg_body.CollisionGroup = GROUND_COLLIDES_WITHEndMethod UpdateGame:Void ()If ballcamera.PointAt (ball)EndifIf explodedIf ballball.Alpha = ball.Alpha - 0.15 ' Very subtle fade hides the join between there and not-there!If ball.Alpha <= 0.0ball.Destroy ()ball = NullEndifEndifEndifEndMethod OnRender (canvas:Canvas) OverrideProcessInput ()UpdateGame ()RequestRender ()If run_physics' CHECK_ME' Nope!'Print b_body.LinearVelocity' Nope!If b_body.AngularVelocity <> New Vec3f (0, 0, 0)lastvel = b_body.LinearVelocityEndifscene.Update ()Endifscene.Render (canvas)canvas.DrawText (App.FPS, 20, 20)If Not run_physics Then canvas.DrawText ("Hit SPACE to drop glass ball! Only runs once...", 20, 60)EndMethod ProcessInput:Void ()If Keyboard.KeyDown (Key.LeftShift)camera_boost = SHIFT_BOOSTElsecamera_boost = 1.0EndifIf Keyboard.KeyHit (Key.Space)b_body.ApplyImpulse (New Vec3f (0.0, 0.0, -10.0))run_physics = TrueEndifIf Keyboard.KeyHit (Key.Escape) Then App.Terminate ()If Keyboard.KeyDown (Key.A)camera.Move (0.0, 0.0, 0.1 * camera_boost)EndifIf Keyboard.KeyDown (Key.Z)camera.Move (0.0, 0.0, -0.1 * camera_boost)EndifIf Keyboard.KeyDown (Key.Left)camera.Rotate (0.0, 1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Right)camera.Rotate (0.0, -1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Up)camera.Rotate (1.0, 0.0, 0.0, True)EndifIf Keyboard.KeyDown (Key.Down)camera.Rotate (-1.0, 0.0, 0.0, true)EndifEndEndFunction Main ()' Windowed mode...Local width:Int = 640Local height:Int = 480Local flags:WindowFlags = WindowFlags.CenterNew AppInstanceNew Game (AppName, width, height, flags)App.Run ()EndMay 16, 2018 at 10:51 pm #14646
A problem I just ran into while trying to add ground collisions — even though collision masks/groups seem to be set up correctly, terrains seem to always trigger the Collided callback, even while not colliding:
Note colliding with ground while falling.
Also note in previous post with no terrain, collisions aren’t erroneously triggered all the time as they are here.May 17, 2018 at 12:14 am #14647
Added landing pads — they recharge your energy level (which currently does nothing when zero), 5 pads in the main area and 5 scattered in and around the mountains — the latter of which in particular highlight the camera limitations for close-up work, unfortunately!
Can’t do ground collisions yet due to the aforementioned problem.May 18, 2018 at 5:13 am #14652
Nice find on the collision detection stuff, I was doing it wrong. Things were actually colliding with terrain even if just bounding boxes intersected, should be fixed now.
Note that CollisionMask and CollisionGroup are bitmasks, each collision type should get 1 bit eg: 1,2,4,8,16 etc. then you ‘or’ together all the types you want to collide with. You may already realize this of course – your demo only uses type 1 and 2 so it’s hard to tell, but I’ll look into making this stuff more intuitive ASAP.
I can probably wangle something with alpha objects casting shadows but there might be some limitations, eg: self shadowing may or may not be a problem. Will look into this too.May 18, 2018 at 7:28 am #14653
Yep, after messing about setting individual bits per the Bullet docs, I finally realised it was just 1, 2, 4, 8, etc and they just needed Or’ing together! I’ve got a few types on the go in the Bust source, not sure if latest upload has the pads, etc, from memory.
It’s not much different to Blitz3D, from what I remember, in that you specify a type (mask) for each object, and a group that decides which types collide. Each group has to include both types in order for a collision to work, eg. the rocket group has to include the terrain type, and the terrain group has to include the rocket type.
(I got the triangle shatter thing going not too badly in a separate thread under Programming.)
Will hopefully get to try the new bits tonight, not going to have much time the rest of this weekend.
Thanks for having a look at shadows… even if alpha shadows disable self-shadowing (?), being able to cast onto other objects should still be an improvement.May 19, 2018 at 1:27 pm #14661
Hacked explosions in on contact with terrain, thanks to recent fix:
Seems to be a weird shadow error on Emscripten at the moment…
Explosions look slightly weird as the cone model turns out to be built from ‘shards’, which I hadn’t expected (as much sense as it obviously makes), but basically work nicely here, spraying out in the direction of travel.
Messy source is on same link as previously.May 20, 2018 at 6:03 am #14665
Shadow weirdness should be fixed now – well kludged around anyway.
It actually relates to this problem, which appears to be a bug in angle and/or the d3d compiler:
I found ‘shaderfrog’ in the process which is kind of fun and should help to narrow down such bugs in future:
Would love to do something like this for monkey2 too!May 20, 2018 at 11:12 pm #14669
Yep, updated/uploaded and shadows look good now, thanks!
Regarding doing something like ShaderFrog, do you mean web-based MX2 coding? I did that for MX1*, and it worked really well, but of course that generated JS code directly within a fraction of a second, whereas MX2 would impose a huge load on a server, what with all the C++ building and Emscripten conversion (especially as soon as just a couple of users are running code at the same time). Not sure how well it would work really!
* Front-end here, back end server no longer present. (The ‘static’ while building is an MX1 app though!)May 22, 2018 at 12:19 am #14675
OK, this is a pretty flucking cool update if you ask me!
I’ve added a rocket model from Google Poly (licensed under CC-BY, ie. freely-distributable, ie. Banana-able eventually) and done a load of fixing to account for its multiple materials, which means that when it ploughs into the terrain it looks fer-hucking beautiful on desktop/decent PC!
However, explosions are unsurprisingly slow as hell on WebGL, so it skips every 3 triangles… and is still slow as hell*:
I highly recommend downloading and building the source for desktop** in order to get the full explosion experience!
It’s only when the full 100% triangle explosion occurs that you can really appreciate it… the WebGL version undersells it considerably!
Massive tidy up next, I think…
* Have since disabled shadows for explosion triangles on WebGL, makes quite a speed difference here. (Not yet in source zip.)
** NB. I use the Github development release.May 23, 2018 at 12:22 am #14684
Nice, rocket model and explosions look cool!
I suspect for max speed for the explosion fragments, you’re probably best manually updating a single model’s vertexbuffer instead of using a Model instance for each triangle, but that’d be a major PITA…
The fragment ‘clouds’ look a bit ‘boxey’ though, I suspect you’re generating velocities via something like Rnd(-1,1) for x,y,z?
You might want to consider normalizing here, eg:
Function FragVel:Vec3f( minSpeed:Float,maxSpeed:Float ) ‘untested!
Return New Vec3f( Rnd(-1,1),Rnd(-1,1),Rnd(-1,1) ).Normalize() * Rnd( minSpeed,maxSpeed )
The normalize steps makes the length of the random vector ‘1’, effectively giving you random points on a sphere.
Also, the fragments are doing something weird when they hit the ground, kind of ‘sticking’ or something, perhaps play around with friction or restitution here?May 23, 2018 at 12:54 am #14686
Literally just finished for the night, but done loads this evening (not that all of it is visible)…
I suspect for max speed for the explosion fragments, you’re probably best manually updating a single model’s vertexbuffer instead of using a Model instance for each triangle
Probably a bit out of my league for now! (Edit: besides, I want them to interact physically with the terrain! I’m considering HTML5 to be just for quick demo purposes, with PC as primary target.)
The rocket trail definitely isn’t doing anything clever yet, so I’ll look at your suggestion there… I’m not seeing the stickiness you are, though! It’s meant to be blocky smoke interacting with the ground, but the spawning/spread definitely needs work…
Anyway, tonight’s update includes:
* Fuel limit!
* Audio! Includes boost, low-fuel alarm and explosion!
* And, on Windows-64-with-Xbox-pad… analogue gamepad control! (Not in web version, highly recommend trying it on desktop.)
Windows 64-bit executable (Have an Xbox controller plugged-in for analogue control! Xbox 360 wired and Xbox One wireless tested.)
Analogue Xbox-pad controls: Left-stick, right trigger. Start resets.
Couple of things I’m struggling with:
* Collision with terrain isn’t always detected right away — entity.Collided (Class Rocket) appears not always to trigger, yet the rocket can sometimes be seen to collide and bounce off the ground; next time it hits it usually explodes. In theory, should just explode on contact every single time. Not sure what this is, since update rate appears not to be the problem, given it bounces, even if it doesn’t explode…
* In relation to entity.Collided, I’m trying to figure out how to determine that I’m not colliding with an object (any more)! Specifically, the rocket.landed result that shows in the display text — hitting a landing pad changes landed to True, but I can’t find any way to clear this back to False after taking off from the pad. (If I set it to False every frame, then it’ll be re-detected every frame — I want to trigger a landing sound once, which is what this variable is for. Trickier than it seems… )
* I wondered if entity.Collided ought to be RigidBody.Collided, feels a bit odd to me, seems like RigidBody should be what collides!
I really need to get in and tidy/separate out my source now, though…May 23, 2018 at 1:12 am #14687
Couple of other things I’ve just remembered:
* I couldn’t figure out how to make it night-time… as in, I set all lights to zero/Color.Black or disabled, AmbientLight to 0, scene ClearColor to 0, but my terrain was still all lit-up like daylight. (Excuse any mis-remembered light/colour refs here.)
* I added a light to my orb, but had to settle for a Spotlight attached to it, pointing down — looks pretty cool when you’re looking for it (particularly after crashes, where it separates and lights up the terrain like a falling torch), but I actually intended a PointLight, which I think is the only one left unimplemented. Think this would look cool as it swings by terrain. (Messing with this is what lead to the attempted night-time scene.)
Think I had more, but gone blank for now.
(I can’t stress enough that the Win64-with-Xbox pad version is way cooler than the web version!)
You must be logged in to reply to this topic.