User Tag List

Results 1 to 9 of 9

Thread: First steps in Movement development

  1. #1
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleXNA Export Module

    Join Date
    Jul 2010
    Location
    Italy
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    First steps in Movement development

    Hi all!
    I'm moving my first steps in MMF2 Movement development. At the moment I'm trying to make a simple movement that moves an object in 360 directions, but what I've written so far gives a strange behaviour. Here it is my Move() function:
    PHP Code:
    BOOL CRunMvt1::Move(LPHO pHo)
    {
        
    LPRO pRo = (LPRO)pHo;

        if (
    pRo->roc.rcSpeed != 0)
        {
            
    pHo->hoX pHo->hoX pRo->roc.rcSpeed cos(m_dir PI 180); //m_dir is not the 32 directions mask, it's the angle between 0 and 359
            
    pHo->hoY pHo->hoY pRo->roc.rcSpeed sin(m_dir PI 180); //used the minus (-) because I want 90 degrees direction to be upwards, and not the opposite
        
    }
        
    callAnimations(pHoANIMID_WALK);
        
    callCollisions(pHo);

        return 
    TRUE;

    If the direction is 315 degrees, the object moves correctly, but if the direction is 45, the object seems to move with angle a little greater than 45 degrees.
    Also, with direction 100, it moves straigt upwards exactly like with 90 degrees.
    What's wrong with my code?
    Thank you in advanced for your help!

  2. #2
    Clickteam Clickteam
    Fernando's Avatar
    Join Date
    Dec 2006
    Posts
    6,128
    Mentioned
    152 Post(s)
    Tagged
    3 Thread(s)
    Sorry to bump in this.

    but the problem seems to be a mix between integer and double, in order to obtain precision you should use double variable X, Y, angle.

    double m_X = pHo->hoX;
    double m_Y = pHo->hoY ;

    m_X = m_X + pRo->roc.rcSpeed * cos(m_dir * PI / 180); //m_dir is not the 32 directions mask, it's the angle between 0 and 359
    m_Y = m_Y - pRo->roc.rcSpeed * sin(m_dir * PI / 180); //used the minus (-) because I want 90 degrees direction to be upwards, and not the opposite

    and after convert both value to the corresponding integer.

    pHo->hoX=(short)m_X;
    pHo->hoY=(short)m_Y;


    check the pinball example

    hope it helps
    Regards,


    Fernando Vivolo

    ... new things are coming ...

  3. #3
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to keep track of your position with double member variables in your movement class, because with FVivolo's code you would get over-time rounding errors, that is, the little rounding errors adding up over time. If you keep double member variables in the movement class then you can maintain precision at all times.
    Working as fast as I can on Fusion 3

  4. #4
    Clickteam Clickteam
    Fernando's Avatar
    Join Date
    Dec 2006
    Posts
    6,128
    Mentioned
    152 Post(s)
    Tagged
    3 Thread(s)
    Yes,

    LB is right, that why is good idea you take a look to the pinball example.
    Regards,


    Fernando Vivolo

    ... new things are coming ...

  5. #5
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleXNA Export Module

    Join Date
    Jul 2010
    Location
    Italy
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your answers! I'm learning from the Pinball example like you suggested me. If I need further help I'll ask here.

  6. #6
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleXNA Export Module

    Join Date
    Jul 2010
    Location
    Italy
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bounce function

    I don't understand some parts of the Bounce function in the Pinball example:
    Code:
        ...
        // Finds the shape of the obstacle
        double a;
        double aFound=-1000;
        for (a=0.0; a<2.0*_PI; a+=_PI/32.0)
        {
            double xVector=16*cos(angle+a);
            double yVector=-16*sin(angle+a);
            double x=m_X+xVector;
            double y=m_Y+yVector;
    
            if (callTestPosition(pHo, (int)x, (int)y, 0, CM_TEST_PLATFORM))
            {
                aFound=a;
                break;
            }
        }
        ...
    From what I've understood (correct me if I'm wrong) it checks for collision in positions around a circle. But I don't understand:
    1) Why aFound starts from -1000?
    2) Why, in the for loop, a is incremented by _PI/32.0?
    3) Why cos and sin are multiplied by 16?

    Thank you again for your help!

  7. #7
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1. In case it never finds an obstacle, -1000 is the sentry value. It could have been anything that wouldn't be in the range returned by the search.
    2 & 3. I think this has to do with either MMF2 using 32 directions at most, or just a way to scale precision.
    Working as fast as I can on Fusion 3

  8. #8
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Phi's Avatar
    Join Date
    Jan 2010
    Location
    England
    Posts
    1,821
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    <SortaCore> magic upvote over-commenting
    * Magic upvoted over-commenting to 9001 on behalf of SortaCore

  9. #9
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleXNA Export Module

    Join Date
    Jul 2010
    Location
    Italy
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LB View Post
    1. In case it never finds an obstacle, -1000 is the sentry value. It could have been anything that wouldn't be in the range returned by the search.
    2 & 3. I think this has to do with either MMF2 using 32 directions at most, or just a way to scale precision.
    Thank you for your answer, now I understood point 1. I'm still not sure about why they used that 32.0 and 16. I also thought 32.0 could be related to the 32 directions of MMF, but the Pinball movement is 360 degrees, so I'm not sure that's the reason. Also, does
    double xVector = 16 * cos(angle+a)
    mean it will check for collision in next 16 pixels? Should I use this value in my movement too?
    Thank you again!

Similar Threads

  1. All Steps Required to Port an MMF2 Game to OUYA
    By redpandagames in forum Android Export Module Version 2.0
    Replies: 4
    Last Post: 28th September 2013, 05:58 PM
  2. How many steps does it take?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 6th June 2012, 01:39 AM
  3. first steps
    By willow in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 25th October 2009, 01:38 PM
  4. First Steps - What am I doing wrong?
    By Faller in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 3rd June 2008, 02:43 PM

Posting Permissions

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