❔ help please
I’m try to make a 2d racing game in visual studio 2022 with C# but I’m have trouble figuring out how to rotate the car in the corners then have it go straight in the direction the front in facing.
12 Replies
Might ask in #game-dev
you should share what you have tried
I would but I’m not at school the rest of the week and forgot to get it on GitHub
lmfao
So...you need to ask specific questions, preferably with c# code examples, to get help. Nobody here can magically figure out your issue based on the extremely general and non-specific way you framed the problem.
Like...I know C#...but I didn't see anything remotely approaching a C# question in your original problem statement. Not trying to be harsh.
The first question would be how would you rotate a rectangle from the middle it
That doesn't seem like a C# question to be perfectly honest.
Maybe a general graphics programming question? Like I have no idea what "middle" refers to
I personally have no experience with graphics programming
I know C# language features. But you seem to be asking something else entirely
If you have a 10 by 10 square how would you rotate it 30 degrees from the middle point
That seems like a general math : graphics question not related to C#. As suggested earlier, someone in #game-dev might know. Or I could try to summon @std::weak_ptr<Akari> or @MD5 who probably understand this kind of thing
It also depends on what platform you are developing your game. Is it unity? Or are you trying to use WPF for this?
Translate so the centre point of the square is at 0,0, rotate, translate back
Say your square is 10x10 and is at 6,6
square.Transform = Matrix.Translate2D(-(3 + 5), - (3 + 5)) * Matrix.Rotate2D(30_deg) * Matrix.Translate2D((3 + 5), (3 + 5))
Exact methods you need to use depend what you're doing it in
The forward vector for this car, the direction you need to move in is then
forwardVector = baseForwardVector * square.Transform
Where baseForwardVector is whatever direction is "forwards" for a non translated squareWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.