Using Velocity to change direction?

Macca_McGillMacca_McGill Member, PRO Posts: 108
edited November -1 in Working with GS (Mac)
Evening,

Im having my actor bounce around the screen as mentioned in other posts, but i want it to change direction everytime it hits a wall (top, bottom, left or right) to a random direction? Can you use the velocity attribute within the actor and if so, which direction is 0?

Cheers

Comments

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Right is Positive on x and up is Positive on y

    Left is Negative on x and down is negative y

    0 is no movement.

    and just to clarify I am talking about self.linearvelocity.x and self.linearvelocity.y

    Hope that helps
  • Macca_McGillMacca_McGill Member, PRO Posts: 108
    Yes thanks. So if the actor bounces off the floor and i want it to go any direction left or right, how would i write that if the scene is 480*320? sorry im not very good at maths haha.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    If you have a collide set it will change direction automaticaly. But it has nothing to do with scene size. If you want it to go up and to the left you need a positive number for the y and a negative for the x etc...
  • micksolomicksolo Member Posts: 264
    Hey JumpBoxGames,

    I would learrn how the X and Y co-ordinates work, you are going to need this a lot!

    The way I learned was by drawing an iPhone screen on a piece of paper and writing where x = 0, y = 0, x = 480 and y = 320, then its easy to find the co-ordinates of any position on screen relative to another position.

    You can also try this free app which will help you a lot too

    http://gamesalad.com/game/idevices
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    micksolo said:
    Hey JumpBoxGames,

    I would learrn how the X and Y co-ordinates work, you are going to need this a lot!

    The way I learned was by drawing an iPhone screen on a piece of paper and writing where x = 0, y = 0, x = 480 and y = 320, then its easy to find the co-ordinates of any position on screen relative to another position.

    You can also try this free app which will help you a lot too

    http://gamesalad.com/game/idevices

    While yes you need to know how the coordinates work.

    It has nothing to do with the question you have asked. It sounds to me like you are trying to go the really hard way to have collisions when what you need to do is just put walls around the edge and make your actor collide with the walls.

    If what I said still sounds like its over your head you need to go back the the wiki/help page on this site and the cookbook videos and learn more about using GS. Cause thats really basic stuff.

    Sorry mate but you gotta walk before you can run.

    Good luck. I hope that helps you.

    Aaron

    ___________________________________________________________________________________
    TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!

    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • JPickardJPickard Member Posts: 477
    Oooh, Idevices is handy. Is there one for iPad?
  • Macca_McGillMacca_McGill Member, PRO Posts: 108
    yeah sorry im probably trying to make it more complicated lol. It works fine just bouncing around but i feel its too easy. just thought it would make it a bit harder if it bounced back off the wall in a different direction? Sometimes when it bounces from the top and hits the side it wont bounce off it will just slide down the wall haha.
  • micksolomicksolo Member Posts: 264
    hey JumpBox, I had this problem in one of my games. What I did was I made an actor in the shape of a box (which was just a smaller version of the wall), turned collision on against the ball, and I placed it on screen, rotated it 45 and then placed it in the corners so if the balls did slide up and down on the walls, they would bounce away when hitting the corners.
  • Macca_McGillMacca_McGill Member, PRO Posts: 108
    ahhh thats a good idea :) Thanks micksolo!
Sign In or Register to comment.