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.
Results 1 to 3 of 3

Thread: random movement

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    6
    Thanked 0 Times in 0 Posts

    random movement

    Hi, I am tring to make an object move across the screen randomly..I want it move up-down left or right acording to the values created..for example I want my object move between value (-5 and +5 ) whats wrong with this ? because it always moves downward ???
    thanks ?

    [AS]
    on(press)
    {
    dur=setInterval(kos,200);
    function kos(){
    var rn1=Math.floor(Math.random()*(5-10))+10;
    var rn2=Math.floor(Math.random()*(5-10))+10;


    _root.car._x+=rn1;
    _root.car._y+=rn2;

    kutu.text="..."+rn1+"..."+rn2;
    }}





    [/AS]

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Can I see the whole code and maybe an example?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    6
    Thanked 0 Times in 0 Posts
    ok.. I solved the problem...as
    var rn1=Math.round(Math.random()*-10)+5;
    var rn2=Math.round(Math.random()*-10)+5;
    thanks..


  •  

    Posting Permissions

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