DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    3

    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
    Posts
    37
    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
    Posts
    3
    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
    Posts
    3
    Got it now

  5. #5
    Join Date
    Mar 2004
    Posts
    635
    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

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links