Stopping Gravity

ThemixedkidThemixedkid Member, PRO Posts: 14

As I don't want all my objects to be affected by a scene gravity, I have instead made an object accelerate off screen.

As I dislike the built in "pause" of the game, I have created my own. This changes everything's velocity to 0, and freezing them in place.

Unfortunately, the item that is affected by the acceleration gravity seems to be exhibiting odd behavior.
When it should be frozen in place, it very slowly keeps going down.
I've set the new acceleration to 0 with the position being the x y coordinates of itself. Yet, there seems to this very slight gravity pull.

Any idea why this is doing this?

Comments

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    Its pretty common trying to stop an actor and it still moving but it can be fixed.

    Have you tried wrapping the move behaviour inside a rule for eg if pause is false....move...so when you press pause change the game.attribute pause to true.

    You could try constraining the motion.linear.x and y but my favourite trick is simply to use move behaviour and set it to speed 0

    I'm not a fan of using scene gravity and tbh never used it in any of my projects.

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    @DeepBlueApps said:
    Its pretty common trying to stop an actor and it still moving but it can be fixed.

    Have you tried wrapping the move behaviour inside a rule for eg if pause is false....move...so when you press pause change the game.attribute pause to true.

    You could try constraining the motion.linear.x and y but my favourite trick is simply to use move behaviour and set it to speed 0

    I'm not a fan of using scene gravity and tbh never used it in any of my projects.

    Currently what I have is a pause boolean that when true, changes the acceleration of the object. The speed is changed to 0, with the position set to its own x, y coordinates.

    I'm not quite sure what you're suggesting.

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    Can anyone offer any suggestion?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    When you say speed set to 0 how are you doing that? Have tried directly changing the actors X and Y Velocity to 0?

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    @jamie_c said:
    When you say speed set to 0 how are you doing that? Have tried directly changing the actors X and Y Velocity to 0?

    How would one go about doing that?
    I am currently utilizing the "accelerate towards the point: self x and self y, with acceleration 0".
    My assumption was that this would stop all motion of the actor.

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    In your pause button I'm presuming you have a game.integer called pause and in your rule you have if touch is pressed change game.pause to (game.pause+1)%2 this will cycle through 0-1-0-1 every time you press the pause button.

    Make a rule and do if game.pause = 0 (move, accelerate or what ever) and in the otherwise section simply do a change motion.linear.x and y to 0 or like I said above do a move attribute and set the speed to 0, you could try constraining motion but there's really no need IMO.

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    @DeepBlueApps said:
    In your pause button I'm presuming you have a game.integer called pause and in your rule you have if touch is pressed change game.pause to (game.pause+1)%2 this will cycle through 0-1-0-1 every time you press the pause button.

    Make a rule and do if game.pause = 0 (move, accelerate or what ever) and in the otherwise section simply do a change motion.linear.x and y to 0 or like I said above do a move attribute and set the speed to 0, you could try constraining motion but there's really no need IMO.

    The way in which I have set up the pause button is the following:
    There is a boolean that is set to true if the game is paused.
    if true, the acceleration of the object is changed to 0 to its own x and y coordinates.
    If false, it proceeds with other behaviors.

    To me, it makes perfect sense and should work. However, the actor very slowly inches down off screen. Everything else in the scene stops their movement.

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    Is there a reason why your using scene.gravity? not many people use it (i know i don't).

    Saying that i think i have found a fix for you but I'm on a Mac and not 100% sure it will work on Windows.

    Give me 5 i will do a video...

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    How would one go about doing that?

    Add two Change Attribute Behaviors that change the actors self.motion.linearvelocouty.x and .y to 0.

    Im on my ipad now, if you need a demo i can do it later today...

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    @Themixedkid Here's a video, basically unlock the pause button actor to access the scene gravity change it to 0 and then change it back to default.

    @jamie_c (i think) He's using "Scene" gravity so the usual tricks won't work.

    Hope this helps.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited May 2015

    (i think) He's using "Scene" gravity so the usual tricks won't work.

    @deepblueapps, I see. Can you clarify @Themixedkid? Are you using Scene Gravity or did you use Accelerate Behaviors (or other behaviors) to create your gravity?

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    @DeepBlueApps said:
    Themixedkid Here's a video, basically unlock the pause button actor to access the scene gravity change it to 0 and then change it back to default.

    jamie_c (i think) He's using "Scene" gravity so the usual tricks won't work.

    Hope this helps.

    I'm not using scene gravity...
    I'm having each item accelerate to a point off the scene.

  • ThemixedkidThemixedkid Member, PRO Posts: 14

    @jamie_c said:
    deepblueapps, I see. Can you clarify Themixedkid? Are you using Scene Gravity or did you use Accelerate Behaviors (or other behaviors) to create your gravity?

    I am using accelerate behavior.
    Even without people telling me, I could tell that scene gravity could be a potential problem in the future and did not use it.

  • ThemixedkidThemixedkid Member, PRO Posts: 14
    edited May 2015

    @jamie_c said:
    Im on my ipad now, if you need a demo i can do it later today...

    Thank you for that suggestion.
    I just went ahead and did it.
    I'm still experiencing the same behavior.

    Most of the gravity does indeed stop, but ever so slowly it still creeps down.

    Here's a screenshot of what exactly I have. If the game is paused, it sets linear x and y to 0. If not gravity is applied.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Well I kind of hate to dig this tutorial out of the archives, it is literally my very first ever GS tutorial about how to completely stop an actor. At the time I was having a problem similar to yours and I used this method to fix it.

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    I'm still convinced a simple move behaviour with speed set to 0 is best like I originally said not sure why you haven't tried it :)

    2:00 mark in the video above replace your change motion linear velocity x and y for move speed 0.

    Anyway hope you get it sorted...

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @deepblueapps, I'd think it has to be more simple than the tutorial I posted too. While it will work, it seems like it's a bit overblown and should be un-necessary. That's a first tutorial for you... LOL!

  • ThemixedkidThemixedkid Member, PRO Posts: 14
    edited May 2015

    @DeepBlueApps said:
    I'm still convinced a simple move behaviour with speed set to 0 is best like I originally said not sure why you haven't tried it :)

    2:00 mark in the video above replace your change motion linear velocity x and y for move speed 0.

    Anyway hope you get it sorted...

    you're absolutely right that worked. I was having trouble understanding you because I didn't know there was a behavior literally called move. I set the move in direction as 0 with speed 0 and it's frozen the actor in place like it should. THANK YOU!

    @jamie_c
    Thank you for that wonderful tutorial, it actually helped me understand things better.

    You two are fantastic, you're my go to people in the future!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited May 2015

    Nice one I was convinced my little trick would sort it as I've used it many times before, at 1st I was confused because I thought you were using scene gravity :) well we got there in the end and I should of been clearer about "move" well done for getting it fixed and good luck with your game.

    I actually learnt something trying to help you so win win, I didn't think you could change scene gravity back and forth but turns out you can :) and i have a cool idea for a template using scene gravity now :)

Sign In or Register to comment.