Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34
  1. #31
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have found this

    Code:
    with instance_create(
        x+lengthdir_x(80,image_angle),
        y+lengthdir_y(80,image_angle),obj_bullet)
    {
     xspeed=lengthdir_x(10,other.image_angle)
     yspeed=lengthdir_y(10,other.image_angle)
    }
    or this one

    Code:
    with instance_create(
        x+lengthdir_x(80,image_angle),
        y+lengthdir_y(80,image_angle),obj_bullet)
    {
     xspeed=cos(other.image_angle*pi/180)*10     //convert degrees to radians when using these
     yspeed=-sin(degtorad(other.image_angle))*10 //i think the y component needs to be flipped
    }
    but I can't match it with your code.

  2. #32
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    *sigh*

    Okay look at that code:
    Code:
    if ( x==0 || x==xmax || y==0 || y==ymax ) 
    { 
        bug.xspeed = - bug.xspeed; 
        bug.yspeed = - bug.yspeed; 
    }
    That can be read as "if EITHER the x or y position reaches EITHER the smallest or largest allowed value, then reverse the direction of BOTH the x and y movement."

    CLEARLY that is NOT what you want. You want to reverse the x direction if x reaches the limits and *separately* reverse the y direction if y reaches the limits.

    So very very simply:
    Code:
    if ( x==0 || x==xmax ) 
    { 
        bug.xspeed = - bug.xspeed; 
    }
    if ( y==0 || y==ymax ) 
    { 
        bug.yspeed = - bug.yspeed; 
    }
    TRY IT!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  3. #33
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you, it works perfectly.

    I will learn javascript one day, I promise.


  4. #34
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Now where in the world did you find that picture of me?

    Of course, that was taken some time ago, while I still had a little hair on my head. (On the back; it doesn't show in that picture.)

    <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


 
Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

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