dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: trajectory,help?!?!

  1. #1
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227

    trajectory,help?!?!

    Hello, I need help with a super game that I am doing involving online gameplay with multiple players. But...there is a problem. I still have to put in some codes, and one I dont know how to do. The one I need help with is a code for trajectory. An example is the game "Interactive Buddy". How you can click and drag a trajectory with the grenades or anything to throw. I need that! Please help me?!?!?!
    Excuse my horrible spelling....you can blame my English teacher for that!

  2. #2
    FK Official Postman
    Join Date
    Apr 2001
    Location
    Rockville, MD / UCSanDiego
    Posts
    827
    I'll give you a explanation of the physics behind it since im not too familiar with your code. It's straightforward enough that you can adapt it, however.

    If we're talking about the path over time, there will be two components - x and y. Also, we're assuming there's no air resistance (which is much easier)

    -X. In this direction, velocity is constant. Thus, if the x velocity was 20px/s at launch, it would remain that way through the course of flight. Thus, you could simply have a loop that, each time a new frame entered (onEnterFrame or similar) would move the object by the x velocity (in pixels/frame)

    -Y. In the y direction, your velocity negatively increases by g pixels/second. To move the object in the y direction, each frame, decrease the velocity by g/framerate and move down that amount...make sure to perform both calculations each frame.

    So now...how do we go from an angle and overall velocity to x and y velocities? Simple...trig! V*cos(angle) = x velocity, V*sin(angle) = y velocity.



  3. #3
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    thanks, its a little clearer, ive had to deal with trig before, but I am only in Algebra 1 right now cuz im a Freshman. But thanks, it seems a little easier.
    Excuse my horrible spelling....you can blame my English teacher for that!

  4. #4
    FK Official Postman
    Join Date
    Apr 2001
    Location
    Rockville, MD / UCSanDiego
    Posts
    827
    Alright, no worries. Let me know what points seem muddy to you and I can explain in more detail.



    I started on FK around the same time, end of 8th grade!


  5. #5
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    I found a great example of trajectory! I need something like in Heli Attack 3! With the arrows, i need them to have gravity and speed like that! Can any one help me!?!?!?!
    Excuse my horrible spelling....you can blame my English teacher for that!

  6. #6
    FK Official Postman
    Join Date
    Apr 2001
    Location
    Rockville, MD / UCSanDiego
    Posts
    827
    do you have a link or a screenshot?


  7. #7
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    ya, here is a downloaded version that i downloaded. Hope this helps! I just want to know how they did the trajectory for the arrows and the guns' bullets. I really want to know how they did this! Please help!?!?! Here it is, the link.
    Excuse my horrible spelling....you can blame my English teacher for that!

  8. #8
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    Here is another example, but a different game. I rather prefer learning how the ppl did Heli Attack 3, but this is an alternative. http://www.big-boys.com/articles/arrowballoon.html
    Excuse my horrible spelling....you can blame my English teacher for that!

  9. #9
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    KB gave you the equations but maybe you just don't know how to implement them.
    V*cos(angle) = x velocity
    V*sin(angle) = y velocity

    In your program, it would be reversed around so that you're setting the variables for velocity and you have to change up the notation a bit for the trig functions.

    xVelocity = V*Math.cos(angle);
    yVelocity = V*Math.sin(angle);

    V is the overall velocity (aka speed) you're trying to get your object to move at. "angle" would be the angle (in radians) that your object is moving in. In this case, angle is pretty much the same thing as the _rotation property except _rotation is in degrees so you have to convert: radians=degrees*PI/180

    Hope this helps
    Neal

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