User Tag List

Results 1 to 10 of 10

Thread: Trajectory Question

  1. #1
    No Products Registered

    Join Date
    Jan 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trajectory Question

    Hi all,

    I have a question. This is the setup:

    There is a Target on screen. It is moving across the screen in a straight line, at some angle (dirT) at some fixed speed (speedT).
    There is a Player object on screen. It is not moving. On a mouse click, it can fire a Missile.
    A Missle moves in a straight line, at some angle (dirM) at some fixed speed (speedM).

    What I want to do, is when I click the mouse the game generates a Missile at the Player object, it knows the DIRECTION (dirM) to set the Missile at, so the Missile (if possible) will intercept/collide with the Target. Keep in mind both the Missile and Target are moving in a straight line, and possibly at different speeds.

    dirM and dirT are 360 deg.

    Does anyone know how to do this?

    JT

  2. #2
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Nov 2006
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    Hmmmmmmm, this would be solved with a linear system. I'm fairly new to the concept and wouldn't know how to implement it in MMF2.

  3. #3
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    Add
    sin(angle)*speed to alterable value A of missile
    Add
    cos(angle)*speed to alterable value B of missile

    set missile x to alterable value a of missile
    set missile y to alterable value b of missile


    The alterable value step is unfortunately necessary because positions are cannot hold decimal values and integers would not move smoothly.

  4. #4
    No Products Registered

    Join Date
    Jan 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    Thanks,

    A few questions,

    How do I return an object's angle? I tried using the Advanced Direction object but couldn't figure it out.

    Come to think of it, how do I SET an object's angle? Isn't MMF limited to 32 directions?

    JT

  5. #5
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    No.

    In the advance direction object go retrieve angle between two points and put in x1,y1,x2,y2.

    Or set angle to sqr((x2-x1)pow 2)+((y2-y1)pow 2))

  6. #6
    No Products Registered

    Join Date
    Jan 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    I couldn't figure out which 2 objects to use to get angle.
    I tried doing all variations of Target/Missile/Player.

    Also, it seems that the formula calculates the dynamic position assuming the Target does not change direction. Is there a formula that calculates the direction (or position) for Missile to intercept Target at the time that Missile is fired? That way, if Target changes direction Missle would have intercepted target had it not changed direction.

    JT

  7. #7
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    Quote Originally Posted by Seele
    sqr((x2-x1)pow 2)+((y2-y1)pow 2))
    That won't get the angle, that's the distance. To get the angle, you'll need an extension. The Clickteam Movement Controller can do it.

    Jellytot: So you want a system to calculate what trajectory a missile would have to take if it wanted to intercept an object, assuming that object will not deviate in its speed or direction?

    I've got a working example, but it's not quite what you'd hope for.

    A) It's actually quite tough to pull off (at least my way is, maybe someone can do a simpler method),
    B) It may not be able to hit the target unless you can vary the speed of the missile.

    The problem is that if the missile goes slower than the target, it's possible for the target to outrun the missile. At best, my system could in this circumstances tell you how far you'd miss it by, which could be used to increase the speed so that you could hit it.

    The system can also tell you the accuracy with which it will fire.

    How it works is thus:

    There's a target at (tX,tY), moving at tSpeed towards tAngle.

    The player fires the missile. The missile is created, and a fastloop starts. This fastloop will be used as a kind of virtual reality, or imagination, for the missile to predict where it and the target will be.

    The missile uses the following alterable values:

    Velocity (its speed)
    Movement Angle (what direction it'll fire in)
    XPOS (its own X position)
    YPOS (its own Y position)
    Predicted XPOS of target (where it imagines the target will be)
    Predicted YPOS of target (where it imagines the target will be)
    Predicted Self Distance (how far the missile itself will have travelled)
    Current Lowest Distance (defaults to 9999999)


    At start, the missile loads the target coordinates into its predictive XPOS and YPOS slots. In every loop that follows, it adds the target's velocity to those coordinates (using trigonometry to adjust for angle).


    At the same time, it keeps adding its own velocity to the Self Distance variable.

    So, basically, each loop will represent one frame in the future. So after 25 loops, it's looking 25 frames into the future.

    These vars enable the missile to 'imagine' where the target will be in X frames time, and compare it to how far it itself will have travelled.

    On each loop, it compares the distance it will have travelled with the distance between missile starting point and the predicted location of the target.

    It selects the one with the lowest distance. Then, it calculates the angle it needs to take (the angle between the missile's origin point and the predicted future location of the target).

    The loop finishes, the missile launches, and a few moments later, they colide.

    It works, but like I said, if the missile is slower than the target, then there are no guarantees that it'll hit its mark.

  8. #8
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module
    Nifflas's Avatar
    Join Date
    Jul 2006
    Posts
    2,613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    You don't need to use an extension to compare the distance between two points though. You can either use this or this method. Using an extension is a bit easier and more CPU friendly, but adding lots of extensions can potentially make your application unstable.

  9. #9
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    THIS should show a working example.

    Remember that if you update the values of the objects so that they go very fast, or that the missile is slower than its target, there will be situations where the two don't meet.

    In the first case, it's because the two would go so fast they 'skip over' each other. (edit: obviously, you'd need to do an in-between movement to avoid this problem).

    In the second case, there will be some angles where the target simply pulls away from the bullet.

  10. #10
    No Products Registered

    Join Date
    Jan 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Trajectory Question

    Wow! Thanks so much!

    JT

Similar Threads

  1. Trajectory is not perfect
    By Pharanygitis in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 9th July 2013, 06:05 PM
  2. Ball trajectory
    By RhysD in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 17th March 2009, 06:03 PM
  3. Trajectory example for Jellytot
    By Dines in forum File Archive
    Replies: 0
    Last Post: 29th April 2008, 04:10 PM
  4. Calculating an arc/trajectory
    By McPhisto in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 24th March 2008, 03:53 AM

Posting Permissions

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