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

  • Home
  • SEARCH
  • 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 1114755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:03:14+00:00 2026-05-17T03:03:14+00:00

I try to work on a Force based 2D ship game. I have Forces,

  • 0

I try to work on a Force based 2D ship game.
I have Forces, that a stored in a Dictionary, for ‘Jets’ on a ship. So I just have to say the name, the amplitude and let the engine do the acceleration/rotation.

For that I have to rotate the force into the local coordinates of the ship, before I can apply it, but instead only rotating the new force, it also rotates the force stored in the Dictionary. What causes the Force to spin around.

Force f1 = new Force();
f1 = Player.JetsDict["RearRight"];
f1.Position = Vector2.Transform(f1.Position, Matrix.CreateRotationZ(Player.Rotation));

while this code dose not change the instance stored in the dictionary (but I don’t want to use it, as its longer, and I got many forces to handle):

Force f1 = new Force();
f1.Position = Player.JetsDict["RearRight"].Position;
f1.Vector = Player.JetsDict["RearRight"].Vector;
f1.Position = Vector2.Transform(f1.Position, Matrix.CreateRotationZ(Player.Rotation));

Why?

Greg the Mad

  • 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-17T03:03:15+00:00Added an answer on May 17, 2026 at 3:03 am

    Since Force is defined as a class (class Force), when you get the copy out of the Dictionary, you’re just getting a reference to a Force instance – the same Force instance that’s stored in the Dictionary. Making a change to members within that reference will be reflected everywhere in your program that uses it.

    The only option here is to make a new instance. This is what you’re doing in the second case.

    However, if the Force is nothing but a Position and a Vector, I would consider making this a struct instead of a class. Structs are always copied by value instead of by reference, which would cause your original code to work the way you expect. If there is more to it, however, a class may still be the best option, in which case the second option is the best potential solution.

    You could shorten it, though, by adding a new constructor that took a Force as an argument, and copied the Position + Vecotr. That would let you write:

    Force f1 = new Force(Player.JetsDict["RearRight"]);
    f1.Position = Vector2.Transform(f1.Position, Matrix.CreateRotationZ(Player.Rotation));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Rails 3.1.rc6 app that I'm using to try to test
OK, I have to make a nim game and try to find the strategy
I try to work with ctags and it simply doesn't work. I follow this
i try to work with spinner on dialog public class data extends Dialog {
I've been struggling all morning to try and work out how mod_rewrite works after
I am a newbie in Python. I try to work with server using Thrift
i try to use jquery .text() but not really work : Before <a id=group_name
I try several samples in the internet and none of them work - the
I try to register to C2DM but it doesn't work. I included com.google.android.c2dm in
I want to learn and work with initialize.php so I try to build simple

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.