Ran into weird problem with Thrust game, where I have to call Scene.Start followed up Scene.Update in order for impulses applied to my gems on startup to work. (They must be called prior to applying impulses, specifically.)
Without doing this, they simply don't appear on screen, though are still present/accessible in-source.
I think I've narrowed it down to this sample, although the same Start/Update fix doesn't work here, but it should be enough to show something's not quite right.
In Debug mode, this will work as expected -- spawn some cubes and apply a fixed impulse.
In Release mode, the cubes don't appear.
In Thrusting Game, after the above 'fix', they intentionally keep spinning at a fixed rate while playing, and I cancel out gravity so they hover.
If you comment out the call below to ApplyTorqueImpulse, or replace with a call to ApplyTorque (which doesn't have the same fixed-rate effect I'm after), they do then appear in Release as expected, just without the spin.
I'm not sure why my Start/Update fix works in Thrusting and not here, but it seems like doing this is necessary prior to applying any kind of impulse in Thrusting, in Release mode.
Debug mode 'fixes' Thrusting without needing the Start/Update thing.
(Something to do with how Scene and Entity.Start work, in conjunction with the instant timing needed for Impulse to apply??)
Anyway, this at least demos the "entity-missing-when-impulse-applied" thing, so hopefully if you can figure that out, the rest will fall into place...
Again, works as expected in Debug.
' Debug: Works
' Release: No cubes unless you comment out this line under ' START LOOP
' c.body.ApplyTorqueImpulse (New Vec3f (1.0, 1.0, 1.0))
' Only seems to apply to impulses (inc. ApplyImpulse)... ApplyTorque works as expected (but doesn't apply fixed spin immediately)...
' Also see comment in Update ()
#Import "<std>"
#Import "<mojo3d>"
Using std..
Using mojo..
Using mojo3d..
Class Cube
Field coll:BoxCollider
Field body:RigidBody
Method New (loop:Int)
Local box:Boxf = New Boxf (-0.5, -0.5, -0.5, 0.5, 0.5, 0.5)
Local cube:Model = Model.CreateBox (box, 4, 4, 4, New PbrMaterial (Color.Red))
cube.Move (loop * 2 - loop * 0.5, 0, 5)
coll = cube.AddComponent <BoxCollider> ()
body = cube.AddComponent <RigidBody> ()
body.Mass = 1.0
End
End
Class Game Extends Window
Field scene:Scene
Field camera:Camera
Field light:Light
Field cubelist:List <Cube>
Method New (title:String, width:Int, height:Int, flags:WindowFlags)
Super.New (title, width, height, flags)
cubelist = New List <Cube>
scene = Scene.GetCurrent ()
camera = New Camera
light = New Light
camera.Move (0, 0, -5)
' START LOOP
For Local loop:Int = 1 To 10
Local c:Cube = New Cube (loop)
c.body.ApplyTorqueImpulse (New Vec3f (1.0, 1.0, 1.0)) ' Comment me out to work in Release!
cubelist.AddLast (c)
Next
End
Method Update ()
If Keyboard.KeyHit (Key.Escape) Then App.Terminate ()
' Comment out ApplyTorque line above and hit I just after running -- this works too...
If Keyboard.KeyHit (Key.I)
For Local c:Cube = Eachin cubelist
c.body.ApplyTorqueImpulse (New Vec3f (1.0, 1.0, 1.0)) ' Comment me out to work in Release!
Next
Endif
End
Method OnRender (canvas:Canvas) Override
Update ()
scene.Update ()
scene.Render (canvas)
RequestRender ()
End
End
Function Main ()
Local width:Int = 640
Local height:Int = 480
Local flags:WindowFlags = WindowFlags.Center
New AppInstance
New Game ("", width, height, flags)
App.Run ()
End
After testing that, try the thing mentioned in method Update (), as that shows it works once the scene is up and running, which may be another pointer in the right direction...
Original Author: DruggedBunny
Hi Mark,
Ran into weird problem with Thrust game, where I have to call Scene.Start followed up Scene.Update in order for impulses applied to my gems on startup to work. (They must be called prior to applying impulses, specifically.)
Without doing this, they simply don't appear on screen, though are still present/accessible in-source.
I think I've narrowed it down to this sample, although the same Start/Update fix doesn't work here, but it should be enough to show something's not quite right.
In Debug mode, this will work as expected -- spawn some cubes and apply a fixed impulse.
In Release mode, the cubes don't appear.
In Thrusting Game, after the above 'fix', they intentionally keep spinning at a fixed rate while playing, and I cancel out gravity so they hover.
If you comment out the call below to ApplyTorqueImpulse, or replace with a call to ApplyTorque (which doesn't have the same fixed-rate effect I'm after), they do then appear in Release as expected, just without the spin.
I'm not sure why my Start/Update fix works in Thrusting and not here, but it seems like doing this is necessary prior to applying any kind of impulse in Thrusting, in Release mode.
Debug mode 'fixes' Thrusting without needing the Start/Update thing.
(Something to do with how Scene and Entity.Start work, in conjunction with the instant timing needed for Impulse to apply??)
Anyway, this at least demos the "entity-missing-when-impulse-applied" thing, so hopefully if you can figure that out, the rest will fall into place...
Again, works as expected in Debug.
After testing that, try the thing mentioned in method Update (), as that shows it works once the scene is up and running, which may be another pointer in the right direction...