Movement based off rotation.

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Movement based off rotation.

  1. #1
    Join Date
    May 2006

    Movement based off rotation.

    Hi i'm trying to make a 2d game where i need the player's x and y positions to update based on the angle of rotation when they move. It's been a good few years since i even thought of programming and have forgotten the math.

    Any help would be much appreciated!

  2. #2
    Join Date
    Mar 2006
    You could have two Variables one called xPos and yPos. It seems to be a very common way to get to set the players position.

  3. #3
    Join Date
    May 2006
    Yes, but i want to move forward the way the sprite is facing rather than straight 4 directional movement.

    I think it has something to do with storing the x and y positions and calculating the sin and cos of the angles but i'm jiggered if i can remember how it goes together.

  4. #4
    Join Date
    May 2006
    Got it now

  5. #5
    Join Date
    Mar 2004
    step = amount the player moves each step
    x += sin(angle)*step
    y += cos(angle)*step

    I might have flip-flop the sin and cos. If the rotation seems backwards, just swap them.

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2007, 12:42 AM
  2. Replies: 1
    Last Post: 11-03-2005, 05:17 PM
  3. Zero based collection
    By pithhelmet in forum VB Classic
    Replies: 2
    Last Post: 04-26-2005, 09:02 AM
  4. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 4
    Last Post: 12-19-2000, 12:52 PM
  5. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 0
    Last Post: 12-19-2000, 11:13 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center