dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Bullet locking onto movieclip

  1. #1
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75

    Bullet locking onto movieclip

    I have a main character movieclip and an enemy movieclip, the enemy only currently plants bomb movieclips which damage the player if touched. I need a long ranged attack for the enemy. Do any of you guys know of a way to make it so when a bullet movieclip is attached to a movieclip and fired it locks in on the x and y position of a main movieclip? Thanks dudes!

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    do you mean like aiming at a moving ennemy?

    if so check and work on this fla
    Attached Files Attached Files
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  3. #3
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    Thanks! I will try to work that code into a movieclip that is used as a bullet and have it lock onto the character movieclip (the kind of bullet that has a Linkage name). Also, the enemy has this coding for the current bomb dropping:

    function timeCheck() {
    if (_root.gotgun2rock == true && !_root.shooting2rock) {

    _root.attachMovie("bullet2", "bulleter2", 3, {_x:_root.enemyrock._x, _y:_root.enemyrock._y-7});

    _root.shooting2rock = true;

    with (_root.bulleter2) {

    onEnterFrame = function () {
    (onClipEvent)
    if (_root.timer2rock>_root.maxshoottime2rock) {
    _root.maxshoottime
    _root.shooting2rock = false;

    this.gotoAndStop("walk");
    unloadMovie(this);

    }
    _root.timer2rock++;

    _x += _root.mvsp2rock;
    _x -= _root.mvsp2rock;


    if (!_root.shooting2rock) {

    _root.timer2rock = 0;

    _root.mvsp2rock = _xscale/20;

    }
    }




    };
    }






    }


    //Setting time!

    myInterval = setInterval(timeCheck, 1500);
    Is there anyway I could make a enemy stop moving (lets say every 9000 milliseconds and go to a frame and null the above code out and then 2000 milliseconds after that make the above code applicable again and repeat? (To make the enemy stop for a short period of time to fire the homeing bullet and then start up again). Thanks.

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    Attached Files Attached Files
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  5. #5
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    Thanks again! I am now using the following in my enemy movieclip:


    onClipEvent (enterFrame) {

    if (_root.timedeadline >= 1000) {
    this.gotoAndPlay("walk2");
    }
    I have the timer setup but it seems to just reply "walk2" every millisecond instead of when the "timedeadline" reaches 1000. Any ideas?
    Last edited by FatherBrandon; 05-10-2006 at 06:03 PM.

  6. #6
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    from the moment "condition 1" gets true : _root.timedeadline >= 1000

    "code action", do this --> this.gotoAndPlay("walk2");

    your problem is that condition 1 remains true all the time --> its looping in your code action

    --> got to find a way to get out of it
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  7. #7
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    All right, I was trying some new stuff when I got back from work. This is currently what I have tried.

    I set a "_root.counter.text" in the main timeline, it is = to 0.

    In the enemy movieclip:

    onClipEvent (enterFrame) {



    if (_root.timedeadline >= 1000) {
    this.gotoAndPlay("hit2");
    _root.counter.text = 150;

    } else if (_root.counter.text <= 150) {
    _root.counter.text = 0;
    this.gotoAndPlay("walk2");

    }
    The counter went to 150 instantly but nothing was being done, I need the "hit2" frame to play out completely, but it only jiggles around on the first frame of it and keeps repeating because of the "if (_root.timedeadline >= 1000)" being detected every millisecond. Any more help is greatly appreciated. I am trying, just have a really busy schedule (I am sure all of you do too, but lots of you can spot actionscript faults right away and help correct them).

  8. #8
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    have in init: _root.timedeadlineReached = 0

    Code:
    if ( (_root.timedeadline >= 1000)  and (_root.timedeadlineReached == 0) ){
    this.gotoAndPlay("hit2");
    // this to get out of this loop
    _root.timedeadlineReached = 1
    
    } else if (_root.timedeadlineReached == 1 {
    this.gotoAndPlay("walk2");
    // this to get out of this loop and go back into the first one
    _root.timedeadlineReached = 0
    
    }
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  9. #9
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    Okay, I see one reason why it is still not functioning. I finally decided to make a dynamic text box for the getTimer(); functions and code you had supplied me with in your previous replies. The text never counts down from 5000. I know that in the example you game me the code for the timers were on two different frames. I have the following in the first frame of the main timeline:
    timestart = getTimer();


    timedeadline = timestart + 5000



    Time = getTimer();


    if (Time> timedeadline) {



    timedeadline += 5000

    }


    timetxt.text = "Time remaining: " + (timedeadline-Time)
    Is it not possible to have the above code all together on one frame? My game is only takes up one frame so far. Thanks for all of your help.

  10. #10
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    You really have to get your head on whats happening in the code and not just copy/paste and be surprised if some bit aint doing what you expected.

    The logic is always the same here, so if you dont get it you'll be asking the same question here again and again until geting everybody tired of repeating the same thing. So read, try to make sense out of it and ask for the logic of it and not lines of code, because if you don't really know watcha doing, every time you'll try to change some lil bit, you'll get stucked.

    So the logic here is:

    Find a way to use some part of the code only once.

    3 differents methods:

    1) put the code on a frame with a loop or a stop() and jump to another frame when condition has been applied. Thats the best to get out of one piece of code and for the cpu not to have to check if statements that are needed only once.

    2) create a if statement and cancel it once it has been applied (example below)

    3) find a method that works the best with watcha doing.


    So, just put that part within a if:

    Code:
    timestart = getTimer();
    timedeadline = timestart + 5000
    -->

    Code:
    if (gettingDatas == 0) {
    
    timestart = getTimer();
    timedeadline = timestart + 5000
    gettingDatas = 1
    
    }
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  11. #11
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    I don't always ask for code, you just choose to supply me with it and I do try to understand it. I spend thirty minutes a day coding, the rest is spent doing art and music (my strong points) for portfolios, I just like to get in a little coding on the side. Don't just assume I mash it in and hope it works. Thanks for the help, I will be taking a closer look at the code this weekend. For future referance, I would love if you talked about code theory instead of supplying the actual code itself.

  12. #12
    Youbackalyte
    Join Date
    Apr 2006
    Location
    Rome
    Posts
    75
    All right, When you said "from the moment "condition 1" gets true : _root.timedeadline >= 1000" it plays and loops the action, that is slightly different from what is happening to me. In my test so far it seems to think that if I supply:

    if (_root.timedeadline >= 100) {

    *insert any code here*

    }

    in the "onClipEvent (enterFrame)" of the enemy movieclip that it equals "_root.timedeadline >= 100" immediatly when the movie loads, it doesn't give the timer a chance to reach "100 or less" before the code inside of the above if statement is played through. I know I am missing something, so if you could help me with the code theory regarding this it would be awesome, no need to fix the code for me, but just explain if you can. Again, I really appreciate the help. I do not want to come off as one of those people who just keeps wanting more and more code without understanding it first, I apologize if I did in my previous posts.

  13. #13
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    When I started with Flash (the world was in black and white in those days) I had problems when working with just one frame, so I always have it now with two frames and a gotoAndPlay(1) as you can see in the fla I already posted. Just felt that Flash was lazy or not good at refreshing stuff, even variable.

    So if you got just one frame, the code is waiting for you to do stuff (like click a button) to do anything.

    So I guess here you need a loop to force the code to check the time all the time.

    My main advice will be: when you try to implement any new function in an existing code, first, create a new blank document and test just the new code with nothing else in it. Just to make sure that you got it right and working and to make sure that you can customize it easily (proof that you fully understand it).

    It can get hard when you're combining lots of function and variables in the same project, usually it's just one lil problem that is causing everything to crash.

    So stuff your code with traces just to check if the code goes to the part of the code you want it to go, and if it doesnt then focus on that specific problem.

    So, if (_root.timedeadline >= 100) is return to be true, it could be simply that between the time, _root.timedeadline was initialized and the moment it's tested, 100 milisecond was spent. --> just set it to 5000 to check it on 5 second. And why setting it to 100? thats quiet short. Have you got it clear that 1000 = 1 second.

    You problem can be lot of things really, but you're the only one to know where you're going. And if it still refuses to work, just start all over again from scratch to get a neat code and check if each step works.

    Good luck anyway
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center