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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:17:30+00:00 2026-05-30T05:17:30+00:00

I have the model representing the player’s ship gradually leaning when the player strafes.

  • 0

I have the model representing the player’s ship gradually leaning when the player strafes. For instance, here’s the code that leans the ship right:

In Update() of the Game class:

if (ship.rightTurnProgress < 1 && (currentKeyState.IsKeyDown(Keys.D)))
{
    ship.rightTurnProgress += (float)gameTime.ElapsedGameTime.TotalSeconds * 30;
}

In Update() of the Ship class:

if (currentKeyState.IsKeyDown(Keys.D))
{
   Velocity += Vector3.Right * VelocityScale * 10.0f;
   RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) * 
     Matrix.CreateRotationY(0.4f * rightTurnProgress);
}

This is what I’m attempting to do to make it ease back out of the lean when it stops strafing:

In Update() of the Game class:

if (ship.rightTurnProgress > 0 && currentKeyState.IsKeyUp(Keys.D))
{
    ship.rightTurnProgress -= (float)gameTime.ElapsedGameTime.TotalSeconds * 30;
}

In Update() of the Ship class:

if (currentKeyState.IsKeyUp(Keys.D) && rightTurnProgress > 0)
{
    RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) *
      Matrix.CreateRotationY(-0.4f * rightTurnProgress);
}

Since easing into the lean works no problem, I thought easing out of the lean would be a simple matter of reversing the process. However, it tends to not go all the way back to the default position after a long strafe. If you tap the key, it snaps all the way back to the full lean of the -opposite- direction. This isn’t what I expected at all. What am I missing here?

  • 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-30T05:17:32+00:00Added an answer on May 30, 2026 at 5:17 am

    I suggest you represent the rotation of you ship as a quaternion. That way you can use an interpolation function such as slerp. Simply have a second quaternion that represents you targeted lean angle and the ship will smoothly rotate until it achieves the targeted angle.

    Here’s a good tutorial on quaternions. If you want to avoid quaternions use MathHelper.Lerp to smoothly transition from the current value to the target.

    if (currentKeyState.IsKeyDown(Keys.D))
    {
        ship.TurnProgress = MathHelper.Lerp(ship.TurnProgress, 1, somefloat * timeDelta);
    }
    else if (currentKeyState.IsKeyDown(Keys.a))
    {
        ship.TurnProgress = MathHelper.Lerp(ship.TurnProgress, -1, somefloat * timeDelta);
    }
    else  (currentKeyState.IsKeyDown(Keys.D))
    {
        ship.TurnProgress = MathHelper.Lerp(ship.TurnProgress, 0, somefloat * timeDelta);
    }
    

    Edit: Also there is a GameDev stack overflow so check it out if you have more questions.

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

Sidebar

Related Questions

I have a model that contains a boolean field representing the item's approval or
I have been wondering whether there is any code out there that enables representing
I have a model representing a Content item that contains some images. The number
I have a datastore model representing items in an ecommerce site: class Item(db.Model): CSIN
I have model Article it has field title with some text that may contain
In my controller I have model operations that can return empty results. I've setup
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
I have a django model and a field representing a users full name. My
I have a mongoose model in my node.js application, representing invoices. I have figured
In my WPF application data model I have multiple classes representing data for interaction

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.