Results 1 to 11 of 11

Thread: Physics or BrainmanagerAI?

  1. #1
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default Physics or BrainmanagerAI?

    I've built a box out of the example physics test level.

    Turn one testing box inside the main box field using lua into a animated ball that I wanted to bounce around the level at various set speeds but never loose or gain speed. just bounce around at a steady pace.

    By default it animates and slowly very slowly.. falls down. it lands on a corner of a box and rotates. All of that is perfect.

    I've tried build on that by using addforce, changing density, to get the ball to move faster and not slow down while it bonces around.
    The only code to respond was the ignore gravity where by it floats in place.
    I've been reading the documentation and searching the forum and even got UltraEdit and did a file search in all the world folders of use of 'AddForce' and only found my lua file made use of the code. (which is odd cuz i think i saw it used in the beer cans example)

    So did I search the wrong word or place? or the examples use different code for physics like Brainmanager as I saw somewhere on the forum?

    I remember another example tests with falling coins and barrels i think... I'll look through and see what i can gather from those examples but I think i need a lil more specific explanation to figure out what I'm missing.

    I'll attach my lua for the ball I applied to one of the boxes.

    Large Ball lua file
    http://apps.facebook.com/files/shared/mao37800ry

    Popped Lua. (later script to be called in lball.lua)
    http://apps.facebook.com/files/shared/n3r6lo5qnb

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,340

    Default

    Hmm. It may be possible to get the direction of movement, kill all force, then restart it again at the desired speed every frame -

    But it seems like the "proper" way to do this would be to create a frictionless material for the both the ball and the things it bounces against. (This part sort of depends on how Box2D works.. not totally sure)
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    Fixed one of my problems.
    I've gotten the ball to drop at a reasonable rate by simply moving some of my code out of OnInit to PostInit.

    It was one random idea I had while staring at the code and trying to figure out the systems and why the code i was using was accepted but not all of it made visable changes xD...

    this:SetDensity(2);
    this:AddForce(Vector2(20,0));
    moved to postinit got a decent movement. now to remove friction and reduction of speed over time some how and I should be set...

    Thx for the insight. Got me thinking differently then before.

  4. #4

    Default

    On my breakout clone, I only to make sure, check on every frame if the amount of kinetic energy is below a threshold, and then I accelerate the ball as needed...

    Unfortunately, I cannot explain to you how to do that with Lua, I added some stuff on Novashell to allow that (before, I used reading the speed directly, but that only works if rotation physics are disabled, because as a object rotate, it converts speed in rotation, maintaining kinetic energy but losing speed, thus if you accelerate it, you add more kinetic energy to the body, and if it suddenly stop spinning, it will get to SUPERSPEEEEED )

  5. #5
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    I think I could figure out the code for constant "push" but using addforce and such isn't "pushing" the ball...

    Not quite sure where to go with this just yet... haven't been experimenting with codes.

  6. #6
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    Got an idea thx to some previous code used in Troll AI..
    I tried to call on addforce again and again since the ball only moved freely after i set some code in postinit. I decided to re-call addforce to see if it still get's ignored.

    With this the ball gets pushed around into bottom right corner randomly every few seconds which is progress...

    function OnPostInit() //run during the entity's first logic update

    //this:GetBrainManager():Add("StandardBase", "");
    this:SetDensity(3);
    this:SetDampening(-1);
    this:AddForce(Vector2(20,0));
    SetupHop()
    end

    function OnKill() //run when removed

    end

    function SetupHop()

    this:AddForce(Vector2(20,20));
    Schedule(random(500,5000), this:GetID(), "SetupHop()");

    end
    Now what i want to do give it one good hard shove and watch how the physics work so I can some ideas on how to code getting the proper result... but if I remove Scheudle the ball never moves and just falls. Ignoring the 2 addforce already in place.

    And speeder mentioned tracking the balls speed. I'm guessing i'd use a log msg but not sure how to log the current speed for me to observe... and without spamming the console...

    Trying code below to track speed for now. wish me luck xD

    LogMsg("Whee! We're moving at " .. tostring(this:GetLinearVelocity()));

  7. #7
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    Log msg worked like a charm although some errors started appearing with it after a minute or so... And was curious if there is a answer for some other things.

    The error i get over a minute or so.
    Whee! We're moving at X:3.50 Y: -3.63
    fixing bad angle in 116, angle is -119.89
    Whee! We're moving at X:3.50 Y: -3.63
    Whee! We're moving at X:3.50 Y: -3.63
    fixing bad angle in 116, angle is -119.93
    Whee! We're moving at X:3.50 Y: -3.63
    fixing bad angle in 116, angle is -119.95
    A quick test showing ball velocity logic. and minor code execution
    Initting gamelogic object
    postinit start
    Whee! We're moving at X:20.00 Y: 0.00
    postinit
    Whee! We're moving at X:20.00 Y: 0.00
    Whee! We're moving at X:0.00 Y: 0.16
    Whee! We're moving at X:20.00 Y: 20.16
    Whee! We're moving at X:17.99 Y: -4.54
    Whee! We're moving at X:-11.86 Y: -1.73
    Whee! We're moving at X:-11.86 Y: -1.73
    Whee! We're moving at X:8.14 Y: 18.27
    Whee! We're moving at X:-0.46 Y: -4.75
    Whee! We're moving at X:-0.46 Y: -4.75
    Whee! We're moving at X:-0.46 Y: -4.75
    Just after postinit start it says it's moving at 20,0 but the ball is never actually moving.

    when it actually gets 0,.16 the ball is doing it's old slow fall it did in the past.
    THEN when addforce is called again it takes off flying... 20.00 Y: 20.16

    This sorta leaves me confused. so (in a separate test) "Oninit" and in this case "Postinit" pretend to have the ball moving? why?

    And I believe that at 0.00 Y: 0.16 the schedule was called and pushed the ball rather then the addforce listed above the schedule...

    Yes i just tested this addforce only executes after the first schedule recall.
    It also seems in one test even after recall the ball didn't take off until it managed to free fall for 1 logic tick I suppose it's called...

    The physics have some sorta delay before kicking in? Can I load them in advance?

    //control how it looks
    this:SetVisualProfile("~/lball.xml", "lball");
    //collision will be loaded/stored here, it's ok if it doesn't exist yet
    this:LoadCollisionInfo("~/lball.col");
    this:SetCollisionScale(Vector2 (1,1));
    this:SetDesiredSpeed(m_walkSpeed);
    this:SetDampening(0);
    this:SetGravityOverride(0);
    this:SetEnableRotationPhysics(true);
    this:AddForce(Vector2(20,0));
    LogMsg("Whee! We're moving at " .. tostring(this:GetLinearVelocity()));
    LogMsg("Oninit");


    if (thisata():Exists("Pop")) then
    //we've been popped
    SetupPop();
    end

    //m_followID = C_ENTITY_NONE;

    //this:SetSpriteByVisualStateAndFacing(); //don't need this, but makes them face the right way before any logic is run

    end

    function OnPostInit() //run during the entity's first logic update

    LogMsg("postinit start");
    //this:GetBrainManager():Add("StandardBase", "");
    this:SetDensity(3);
    this:SetDampening(-1);
    this:AddForce(Vector2(20,0));
    LogMsg("Whee! We're moving at " .. tostring(this:GetLinearVelocity()));
    LogMsg("postinit");
    Track()
    SetupHop()
    end

    function OnKill() //run when removed

    end

    function SetupHop()

    this:AddForce(Vector2(20,20));
    Schedule(random(700,7000), this:GetID(), "SetupHop()");

    end

    function Track()

    LogMsg("Whee! We're moving at " .. tostring(this:GetLinearVelocity()));
    Schedule(500, this:GetID(), "Track()");


    end
    Now to experiment with tracking direction and giving a constant push or reducing loss of 'kinetic energy'... this will take some thought...

  8. #8
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    maybe it's just late and I'm not thinking straight.
    But counld't I use tostring(this:GetLinearVelocity())) to track if the balls movement in a certain direction is always at a certain speed? and use add force to compensate for loss in speed?...

    hmm...

  9. #9
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    I almost got what I want and I don't even know how I did it...

    Original screensize detected as 1024.00 X 768.00
    Command line parms received:
    H:\Novashell\worlds\TSO_Balls.novashell

    Initializing GameLogic...
    Clanlib Sound System Initialized
    Mounting world path H:\Novashell\worlds\TSO_Balls.
    Updated binary version of H:\Novashell\worlds\TSO_Balls/script/ball1\lball.lua
    Novashell V0.81 and Lua 5.13 RT Edition Initted.
    Initting world
    Ignoring UnloadMapByName, Intro isn't loaded yet.
    Ignoring UnloadMapByName, Game isn't loaded yet.
    Loaded map Intro at tick 0. 5 non-empty chunks, size is 1 by 2.
    Clicked start
    Loaded map Game at tick 753. 12 non-empty chunks, size is 3 by 2.
    Whee! We're moving at X:20.00 Y: 0.00
    Oninit
    Initting gamelogic object
    postinit start
    Track moving at X:20.00 Y: 20.00
    setuphop We're moving at X:20.00 Y: 20.00
    setuphop We're moving at X:0.00 Y: 0.16
    setuphop We're moving at X:0.00 Y: 0.32
    setuphop We're moving at X:0.00 Y: 0.64
    setuphop We're moving at X:0.00 Y: 1.28
    setuphop We're moving at X:0.00 Y: 2.56
    setuphop We're moving at X:0.00 Y: 5.12
    setuphop We're moving at X:0.00 Y: 10.24
    setuphop We're moving at X:0.63 Y: -9.51
    setuphop We're moving at X:1.26 Y: -19.01
    setuphop We're moving at X:2.51 Y: -38.02
    setuphop We're moving at X:0.00 Y: 38.02
    setuphop We're moving at X:0.00 Y: -38.02
    setuphop We're moving at X:0.00 Y: 38.02
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    Track moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    Track moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: 76.04
    setuphop We're moving at X:0.00 Y: -76.04
    Restarting engine...

    Initializing GameLogic...
    Clanlib Sound System Initialized
    Novashell V0.81 and Lua 5.13 RT Edition Initted.
    No mod has overidden script/game_start.lua. Running default, which let's the player choose a world.
    Loaded map hidden_Base Startup at tick 11313. 2 non-empty chunks, size is 1 by 1.
    Editor opened up
    Setting retail to false
    Editor closed
    Restarting engine...

    Initializing GameLogic...
    Clanlib Sound System Initialized
    Mounting world path H:\Novashell\worlds/TSO_Balls.
    Novashell V0.81 and Lua 5.13 RT Edition Initted.
    Initting world
    Ignoring UnloadMapByName, Intro isn't loaded yet.
    Ignoring UnloadMapByName, Game isn't loaded yet.
    Loaded map Intro at tick 13559. 5 non-empty chunks, size is 1 by 2.
    Clicked start
    Loaded map Game at tick 14788. 12 non-empty chunks, size is 3 by 2.
    Whee! We're moving at X:20.00 Y: 0.00
    Oninit
    Initting gamelogic object
    postinit start
    Track moving at X:20.00 Y: 20.00
    setuphop We're moving at X:20.00 Y: 20.00
    setuphop We're moving at X:0.00 Y: 0.16
    setuphop We're moving at X:0.00 Y: 0.32
    setuphop We're moving at X:0.00 Y: 0.64
    setuphop We're moving at X:0.00 Y: 1.28
    setuphop We're moving at X:0.00 Y: 2.56
    setuphop We're moving at X:0.00 Y: 5.12
    setuphop We're moving at X:0.00 Y: 10.24
    setuphop We're moving at X:0.59 Y: -9.46
    setuphop We're moving at X:1.19 Y: -18.93
    setuphop We're moving at X:2.38 Y: -37.86
    setuphop We're moving at X:0.00 Y: 37.86
    setuphop We're moving at X:0.00 Y: -37.86
    setuphop We're moving at X:0.00 Y: 37.86
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    Track moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    setuphop We're moving at X:0.00 Y: 75.71
    setuphop We're moving at X:0.00 Y: -75.71
    setuphop We're moving at X:0.00 Y: 75.71
    Here's the code i used primarily
    Track()
    SetupHop()
    end

    function OnKill() //run when removed

    end

    function SetupHop()
    LogMsg("setuphop We're moving at " .. tostring(this:GetLinearVelocity()));
    this:AddForce(this:GetLinearVelocity());

    Schedule(250, this:GetID(), "SetupHop()");


    end
    Forgot I turned of rotation physics to see what difference it made to animation and physics... ends up bouncing straight across the box which isn't acceptable... =/
    Last edited by TSO; 08-20-2010 at 05:35 PM. Reason: details...

  10. #10
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    Alright with rotation physics it sorta caps a little higher around 100 I think.

    I guess if I find a way to turn off the velocity at a cap of 10 I'll be set.

  11. #11
    Squire
    Join Date
    May 2010
    Location
    Ontario
    Posts
    28

    Default

    Well I made that game in a different editor much more easily... =/

    Glad people are still using my code though to perhaps work on their own projects!

    Sorry for little to no comments!
    I tend to comment everything at the end when my understanding is the most complete.

    Cheers and good luck =)

Similar Threads

  1. Hands on physics control
    By speeder in forum Novashell Game Creation System
    Replies: 3
    Last Post: 07-14-2010, 10:49 PM
  2. Puzzled by the physics...
    By speeder in forum Novashell Game Creation System
    Replies: 3
    Last Post: 05-10-2010, 07:45 PM
  3. Physics Question
    By ShadowDust in forum Novashell Game Creation System
    Replies: 2
    Last Post: 12-29-2008, 08:38 AM
  4. Clanlib physics
    By pTymN in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-11-2007, 04:19 AM
  5. Physics implementation
    By pTymN in forum Novashell Game Creation System
    Replies: 1
    Last Post: 02-09-2007, 04:44 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •