Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:16:29+00:00 2026-05-31T16:16:29+00:00

I have a script in place and running that allows me to move an

  • 0

I have a script in place and running that allows me to move an image along a path, but my path goes off track (on hexagon map) after about 6 moves.

I know there is a function to handle this, but right now I am unable to find what to do. Currently, I am using a set float value for the x and y moves that are anything other than a move up or down (0 degrees and 180 degrees), which are a set integer value.

Here’s my psuedo-code:

function doTranslate(deg, goX, goY) {
   clearCanvas();
   var context = surface.getContext('2d');
   context.save();
   context.translate(goX,goY);
   context.rotate(DegToRads(deg));
   context.drawImage(gamePiece, -10, -10);
   context.restore();
}

Again, this all works, but my calculated values for goX and goY are global variables that get updated based on the direction we are moving.
Right now, I am using a float of 18.3 for my x move, and 9.8 for my y move, and a int value of 21 for my straight up or down moves.

I remember from college (only vaguely) that I need to do some square roots and PI operations in there somewhere, but right now I am just adding and subtracting the static values for each move.

Has anyone already solved this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:16:30+00:00Added an answer on May 31, 2026 at 4:16 pm

    To move something on a hexagonal grid it would have to follow these fundamental units.

    position graph

    To put it in semi-pseudocode:

    s = 10.0; //Scale (how far you want the object to move)
    
    //Move right
    goTo(2*s,0*s)
    
    //Move up-right
    goTo(1*s,Math.sqrt(3)*s)
    
    //Move up-left
    goTo(-1*s,Math.sqrt(3)*s)
    
    //Move left
    goTo(-2*s,0*s)
    
    //Move down-left
    goTo(-1*s,-Math.sqrt(3)*s)
    
    //Move down-right
    goTo(1*s,-Math.sqrt(3)*s)
    

    Now, if you want the hexagon to be oriented up and down instead of left and right, use this code:

    s = 10.0; //Scale (how far you want the object to move)
    
    //Move up
    goTo(0*s,2*s)
    
    //Move up-left
    goTo(-Math.sqrt(3)*s,1*s)
    
    //Move down-left
    goTo(-Math.sqrt(3)*s,-1*s)
    
    //Move down
    goTo(0*s,-2*s)
    
    //Move down-right
    goTo(Math.sqrt(3)*s,-1*s)
    
    //Move up-right
    goTo(Math.sqrt(3)*s,1*s)
    

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems very strange to me but I have a script that I'm running
I have a script that connects to SQL Server 2005 default instance. But I'm
I have a simple bash script running on OS X that removes specific files
I have developed a script in linux bash that is running in background and
I have a long running redgate script that is applying a bunch of schema
I have script which allows to display Bing search results. I can call for
I have some script in my default page that redirects users to language specific
I have a script that checks something on my PC every 5 minutes and
I have a script that will convert a text file into a resource file,
This is a convoluted example so bear with me: I have a script that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.