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 6158889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:02:13+00:00 2026-05-23T21:02:13+00:00

In my game, you can move forward and backwards but I don’t know how

  • 0

In my game, you can move forward and backwards but I don’t know how to side step to the left or right

GLfloat v[] = {[self centerAtIndex:0] - [self eyeAtIndex:0],[self centerAtIndex:1] - [self eyeAtIndex:1], [self centerAtIndex:2] - [self eyeAtIndex:2]}; 

//forward
[self setEye:[self eyeAtIndex:0] + v[0] * SPEED_MOVE atIndex:0];
[self setEye:[self eyeAtIndex:2] + v[2] * SPEED_MOVE atIndex:2];
[self setCenter: [self centerAtIndex:0] + v[0] * SPEED_MOVE atIndex:0];
[self setCenter: [self centerAtIndex:2] + v[2] * SPEED_MOVE atIndex:2];

gluLookAt(eye[0], eye[1], eye[2],center[0],  center[1], center[2], 0.0, 1, 0.0);

Can anyone give me the actual code to make the camera go sideways. I have tried switching the v[2] and v[0] and that does make me move sideways for a couple of angles only, it seems to go the opposite way most the time or even forward.

Solution

float up[3] = {0, 1, 0};
        float forward[3] = { center[0] - eye[0],center[1] - eye[1],center[2] - eye[2] };

        float left[3];
        left[0] = forward[1] * up[2] - forward[2] * up[1];
        left[1] = forward[2] * up[0] - forward[0] * up[2];
        left[2] = forward[0] * up[1] - forward[1] * up[0];

        // now translate your eye position
        [self setEye:[self eyeAtIndex:0] - left[0] * SPEED_MOVE atIndex:0];
        [self setEye:[self eyeAtIndex:2] - left[2] * SPEED_MOVE atIndex:2];
        [self setCenter: [self centerAtIndex:0] - left[0] * SPEED_MOVE atIndex:0];
        [self setCenter: [self centerAtIndex:2] - left[2] * SPEED_MOVE atIndex:2];  


        if (([self eyeAtIndex:2] >= MapSizeZ || [self eyeAtIndex:0] >= MapSizeX  || [self eyeAtIndex:2] <= 1 || [self eyeAtIndex:0] <= 1) || [self checkCollisionWithPoint:CGPointMake([self eyeAtIndex:0] ,[self eyeAtIndex:2])] ){

            [self setEye:[self eyeAtIndex:0] + left[0] * SPEED_MOVE atIndex:0];
            [self setEye:[self eyeAtIndex:2] + left[2] * SPEED_MOVE atIndex:2];
            [self setCenter: [self centerAtIndex:0] + left[0] * SPEED_MOVE atIndex:0];
            [self setCenter: [self centerAtIndex:2] + left[2] * SPEED_MOVE atIndex:2];  
        }
  • 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-23T21:02:14+00:00Added an answer on May 23, 2026 at 9:02 pm

    You can get a vector pointing sideways by calculating the cross product of the up vector (here [0 1 0]) and the “look” vector (here center - eye). From that you get a vector pointing to the right or left side depending on the order. Then just add/subtract that vector to the current camera position (eye, center) in order to strafe.

    Coding it yourself should be fairly easy, the cross product is a simple formula. And there are many fully implemented camera classes available on the Internet.

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

Sidebar

Related Questions

I'm designing a game for windows 8 using HTML5 , but my game can't
I'm working on a browser-game and I can't help but wonder about what's the
I've looked at many collision detection technique for a 2D game but I can't
How can I create board for simple game, looks like for chess,but user could
I'm trying to make a game with Qt, but i can't load an image.
I am currently building a game, where u have controllers which you can move
I'm making a small game and I have a character that can move in
I was trying to make a tank game in which I can move the
I want to make a game where the playing pieces can move around. When
I have a database with users and games. 1 game can have multiple users

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.