Forum Replies Created
- 
		AuthorPosts
 - 
		
			
				
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.
Getting somewhere with this, with a lot of hand-waving…
Messy and still needs a lot of work, eg. triangles’ physics bodies are boxes so they don’t settle right (think I will try build rects from them instead), but at least the ball’s disintegration looks sort-of OK. Ideally it would disintegrate as each triangle intersects the ground, instead of the instant the ball touches the ground, but it’s basically doing what I was hoping for.
The triangles seem to disappear initially, but I think it’s because they turn edge-on, being infinitely thin.
Bit slow on WebGL, unsurprisingly.
In real life, triangles would be replaced with pre-generated model chunks.
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.
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.
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.
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338[crayon-5cba9cf13e69f477357716 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 [3]' mesh-local co-ords...tri_verts [0] = mesh.GetVertex (indices [index + 0])tri_verts [1] = mesh.GetVertex (indices [index + 1])tri_verts [2] = mesh.GetVertex (indices [index + 2])Local tri_indices:UInt [] = New UInt [3]tri_indices [0] = 0tri_indices [1] = 1tri_indices [2] = 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 ()EndJust checking, did you have bg.png in a data subfolder, like this?
[/crayon]Monkey123456[crayon-5cba9cf14be78630589168 inline="true" ]--example.monkey--data/--data/bg.pngDo any of the MonkeyX light samples work, or is it just your own code that’s not working?
I can’t remember what samples are in MX, but seem to recall there was a lights sample. If that doesn’t work, I’d guess the notebook doesn’t support the GL or shader level required for them.
If it’s just your own code, ie. the sample works, probably best to post on the CerberusX forums, since probably very few here are using MX now.
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*
Ahhhh… thanks, Simon, that’s awesome, will try take it in, but I can at least get to work now! Thanks again.
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.
Woo-hoo! Basically got my camera working as intended!
You may notice a jolt if the rocket gets close to the camera and then moves away. I know what this is and believe I can resolve it easily enough — it’s part of how I position the camera position target (point towards which camera moves each frame) according to the rocket’s velocity vector. If this vector is zero (rocket stopped), then I need to use the last significant movement vector in order to have a valid offset for the camera to sit at.
Next step will be a massive clean-up, conversion to new develop version, add a few little objectives (collect the gems, steal the orb, etc) and that should be about it…
It’s still bloody hard, but… it’s Thrust, in 3D. What do you expect?!
Good point, a one-off or even a small monthly amount will help to reward Mark for this awesome work! It doesn’t write itself!
It turns out fixed constraints are springy too which is kind of cool
Gah, was hoping they were actually FIXED! I guess I can use the force offset thingy anyway, still to try that.
But, yeah, might as well require that things are positioned correctly before connecting them, since their physics will have started anyway.
Yeah, I think it makes sense!
(Think I’ve done my pivots back-to-front anyway, should really have attached the ball-socket from the perspective of the rocket, rather than from the perspective of the orb, ie. with orb as ConnectedBody from the rocket, rather than rocket as ConnectedBody from the orb)… I know it works out the same, just makes more sense from a visualisation perspective to have the ball socket attached to the rocket and have orb as the ConnectedBody!)
Done with ****ing cameras for tonight, ****ing thing won’t ****ing do anything other than ****ing settle facing ****ing north! Must be 3 ****ing hours on this ****ing problem now! Off to ****ing bed!
Sorry, think I get what you mean by removing ConnectedPivot, as that would be the ‘fixed’ end (orb end in my case), so guess you can just work that from the ball (rocket-end) Pivot…
 - 
		AuthorPosts