User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Custom 8 direction movement, problems with speed

  1. #1
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,970
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Custom 8 direction movement, problems with speed

    Ok, basically for the player speed, I have a global value, with a default value of 4.

    Basically, my movement is working like this:

    Repeat while [Player moves Right]:
    -Set X Pos of Player to X Pos of Player + Speed

    Then I went and did this for Up, Down, and Right directions, with the appropriate calculations. This allows the player to move around at the desired speed, however, I have noticed an anomaly. When moving at an angle, like say Up+Right, it seems like the player is moving slightly faster than when moving just Up or Right. It happens for all the 4 angle movements.

    I'm a little confused by what is going on. To make things more clear, for Up movement I have:

    Repeat while [Player Moves Up]:
    -Set Y Pos of Player to Y Pos of Player - Speed

    I have tried adjusting the speed when an angled direction is pressed like if Up+Right is pressed, then set Speed to [value], but this didn't work.

    Basically, I want the player to move the same speed whether its the 4 regular directions or the 4 angles in 8 direction movement. At the moment, with what I'm doing, the player moves slightly faster while going one of the angle directions, even though I never change the Speed variable in any events.

    Any ideas?

  2. #2
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,970
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Well for the time being I just stopped trying to do a custom movement and use the built in 8 direction movement. But I'd still be interested to know in why I was seeing a speed difference.

  3. #3
    Forum Moderator Multimedia Fusion 2 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    DizzyDoo's Avatar
    Join Date
    Oct 2006
    Location
    South England
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Speed difference is a problem with the maths. If you think about it, you have the speed of 4 in the X and in the Y, which gives you a resultant hypotenuse (it makes a vector triangle) of almost 6. So yes, your player is moving at 1.5 times the speed it should be.

    What you need for an accurate 8-direction movement is a bit of trigonometry. For the Y, multiply your speed by the sin of the angle...

    4*sin(0)
    4*sin(45)
    4*sin(90)

    ... all the way up to 4*sin(315) in 45 degree increments. Then for the X multiply your speed by the cos of the angle:

    4*cos(0)
    4*cos(45)
    4*cos(90)

    ... and so on again. That will give you an accurate movement.

    Good luck!
    Cranktrain - Currently finishing a new game called The Cat Machine!
    @MattLuard on Twitter.

  4. #4
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,970
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Awesome! Thank you!

    As you can probably tell, math isn't my strongest suit lol.

  5. #5
    No Products Registered

    Join Date
    Jun 2006
    Location
    Land of raging rockets
    Posts
    1,231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    The thing is - as a pixel is square, moving one pixel up, or one pixel right, is shorter than moving one diagonally:

    move right:
    x = 10
    y = 0
    distance = Sqrt(10*10 + 0*0) = 10

    move diagonal:
    x = 10
    y = 10
    distance = Sqrt(10*10 + 10*10) = Sqrt(200) = 14,1421.. = 10 * Sqrt(2)

    So if you want the correct diagonal movement, just divide the speed by Sqrt(2) (the square root of 2, or 2 to the power of 0.5).

    You could do this by determining on how many axises the player moves and use that within the Sqrt() (or whatever it is in MMF):
    speed = 10 / Sqrt(speed_x/speed_x + speed_y/speed_y)
    if he moves on one axis, this will become Sqrt(1) = 1 and on two axises Sqrt(2) and on none Sqrt(0) = 0. Yay

  6. #6
    No Products Registered

    Join Date
    Jun 2006
    Location
    Land of raging rockets
    Posts
    1,231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Thinking about it, if you already have the angle, DizzyDoo's solution is a lot more elegant :P

  7. #7
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,970
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Okay I think I got the calculations down for the angles, but I was wondering what I need to do to implement the speed in MMF.

    Like before I was doing X Pos = X Pos + Speed for moving right.

    So, using the calculation for moving right, I would assume that would be 4*cos(0), so would I do X Pos = X Pos + (4*cos(0))?

    Or am I not understanding this correctly?

  8. #8
    Clicker Fusion 2.5Android Export ModuleiOS Export Module
    Fusion 2.5 (Steam)HTML5 Export Module (Steam)

    Join Date
    Nov 2007
    Location
    Canada, BC
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    use X Pos = X Pos + (4*cos(0))
    Y Pos = Y Pos - (4*sin(0))

    the 4 is the speed
    the 0 is the angle (right = 0, up = 90, left = 180, etc..)

  9. #9
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,970
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Custom 8 direction movement, problems with speed

    Quote Originally Posted by Mook06
    use X Pos = X Pos + (4*cos(0))
    Y Pos = Y Pos - (4*sin(0))

    the 4 is the speed
    the 0 is the angle (right = 0, up = 90, left = 180, etc..)
    Okay thanks!

  10. #10
    Clicker Fusion 2.5 DeveloperiOS Export Module

    Join Date
    Nov 2010
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For some reason this is not working for me. When I move my person down and to the left, he's not moving at a 45 degree angle, and he's moving very slow. I'm using a speed of 2, but when I switch it to a speed of 4 it doesn't change. Does this have anything to do with the fact that I'm trying to move an object a fraction of a pixel?

    XPos = XPos + (Speed*cos(angle))
    XPos = XPos + (2 * cos (225)) which equals -1.41

    Am I doing this wrong?

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Getting Speed in the X Direction from Clickteam Movement Controller
    By amaire13 in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 24th November 2012, 08:07 PM
  2. Custom movement speed problem.
    By DaveC in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 18th February 2011, 08:36 PM
  3. Adjusting speed on custom grid movement (Nivram's)
    By Shawn in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 27th August 2010, 03:58 PM
  4. Problems with 8-Direction Movement
    By Gullyking in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 23rd June 2010, 02:43 AM
  5. Custom 8 Direction Movement
    By JL32BiT in forum File Archive
    Replies: 1
    Last Post: 2nd July 2006, 06:08 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
  •