Questions tagged [c#]
C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.
637
questions
29
votes
1
answer
18k
views
Orienting a model to face a target
I have two objects (target and player), both have Position (Vector3) and Rotation (Quaternion). I want the target to rotate and be facing right at the player. The target, when it shoots something ...
4
votes
2
answers
1k
views
Nestling into contact with a group of physics objects without exerting forces on them
I'm making a pool game, and would like the circle (imaginary) to be in contact with the table and balls, and to fit perfectly as a ball would.
Now I thought I would use Rigidbody and lerp the ...
79
votes
10
answers
229k
views
In Unity, how do I correctly implement the singleton pattern?
I have seen several videos and tutorials for creating singleton objects in Unity, mainly for a GameManager, that appear to use different approaches to instantiating ...
11
votes
3
answers
5k
views
How do I make a 2D game resolution independent?
I'm working on a simple 2D game. I've finished the mobile phone version.
However, my boss wants the game to works on his RT.
I'm doing the "conversion" but my buttons are in the wrong places, because ...
32
votes
3
answers
14k
views
How to properly implement message handling in a component based entity system?
I am implementing an entity system variant that has:
An Entity class that is little more than an ID that binds components together
A bunch of component classes that have no "component logic", only ...
38
votes
11
answers
90k
views
In Pong, how do you calculate the ball's direction when it bounces off the paddle?
I'm trying to wrap my head around this very Hello World-y problem in game development. I've created a TicTacToe game in XNA so I guess the next step would be a Breakout clone.
Keep in mind that I ...
3
votes
2
answers
6k
views
Arrive steering behavior
I bought a book called Programming game AI by example and I am trying to implement the arrive steering behavior. The problem I am having is that my objects oscillate around the target position; after ...
0
votes
1
answer
2k
views
Unity smooth local rotation around one Axis, oriented toward a target
I want to acheive the same rotation you see in the inspector.
In short: a smooth local Y rotation, toward a target
I have a Vector3 orientation:
...
58
votes
9
answers
20k
views
How are deterministic games possible in the face of floating-point non-determinism?
To make a game like an RTS networked, I've seen a number of answers here suggest to make the game completely deterministic; then you only have to transfer the users' actions to each other, and lag ...
21
votes
2
answers
17k
views
How do I disable texture filtering for sprite scaling in XNA 4.0?
I have a sprite that I'm trying to scale up in XNA, but XNA is applying some sort of texture filtering that smooths it and makes it look ugly. I'd like it to just do pixel doubling instead of ...
11
votes
2
answers
6k
views
Microsoft XNA Platformer Example, is the Collsion Detection implemented accurately?
The example provided by Microsoft seems as if the collision detection (from what I can see) will have a small error. When the user collides with an Unpassable tile, the depth of the intersection is ...
9
votes
3
answers
5k
views
XNA - Static classes from game libraries executing after content pipeline extensions, how to avoid the problem?
Alright, formulated this way I'm sure it sounds obscure, but I'll do my best to describe my problem.
First, let me explain what's wrong with my real source code.
I'm making a platformer, and here ...
7
votes
1
answer
2k
views
Turning a sprite such that it rotates in the direction that's most efficient
I have a sprite that moves from waypoint to waypoint. It turns to face its velocity vector, but not instantly (there's a rotation speed).
The problem I'm having is, from one direction to another, the ...
2
votes
2
answers
2k
views
Camera relative movement is pushing into/off the ground instead of parallel
I'm building upon roll a ball tutorial in unity, and I have managed to rotate the camera around the ball just fine with the code below. But there's one problem.
In this code, when I add force to the ...
51
votes
7
answers
11k
views
2D Platformer AABB collision problems
I have a problem with AABB collision resolution.
I resolve AABB intersection by resolving the X axis first, then the Y axis.
This is done to prevent this bug: https://i.stack.imgur.com/NLg4j.png
...
13
votes
2
answers
16k
views
How do I generate projectiles toward the mouse pointer? [duplicate]
I'm making a top-down space shooter where the player controls a ship and can aim and shoot using the mouse cursor. How can I fire bullets from the ship at the angle from the ship to the mouse cursor?
5
votes
8
answers
12k
views
Why is the IntelliSense not working when I open a new script in Visual Studio?
The strange thing is that opened scripts or newly opened ones are working fine. It's the new created C# scripts that are not working.
With not working, I mean the MonoBehaviour is not in light blue ...
4
votes
2
answers
9k
views
How can I accurately simulate orbits in Unity?
I would like to create a space simulation with realistic gravity.
This means planets in 3d space which act as central gravity sources and multiple objects which are attracted by those planets gravity ...
4
votes
3
answers
2k
views
Floor is made up of tiles with their own box colliders. Pushable item gets stuck on the "seams"
So I have a scene where the floor is made up of some tiled objects. All of these have the exact same height and exact same Y position. I also have a block with a rigidbody that you can push on the ...
4
votes
2
answers
6k
views
How to blend biomes with procedural terrain
I'm working on a terrain generator. Through multiple noise functions, I'm able to create many kinds of terrain I like, but I'm having a bit of difficulty joining them together in a seamless fashion.
...
1
vote
1
answer
1k
views
How to assign game object references to a class instance created at runtime?
I'm creating a game where I have an Entity class that contains basic entity info (pos, health,..) and some functions. Enemies and Player later on inherit from this class.
...
1
vote
1
answer
12k
views
UV World mapping in shader with Unity.
Please refer to this Answer.
DMGregory script is working for me, although I have a problem I can't fix because I don't talk shader :)
The tiling will be applied correctly on geometry aligned on XY ...
0
votes
4
answers
101k
views
How to access a variable from another script in Unity c#
I need to access a variable from another script in Unity, but I can't figure it out.
Script:
...
59
votes
1
answer
18k
views
Using component based entity system practically
Yesterday, I've read a presentation from GDC Canada about Attribute / Behaviour entity system and I think it's pretty great. However, I'm not sure how to use it practially, not just in theory. First ...
30
votes
6
answers
13k
views
A way to store potentially infinite 2D map data?
I have a 2D platformer that currently can handle chunks with 100 by 100 tiles, with the chunk coordinates are stored as longs, so this is the only limit of maps (maxlong*maxlong).
All entity positions ...
17
votes
2
answers
13k
views
Inheritance vs Composition
I make my money in C# Generally in that language I like to decouple everything to the high heavens using interfaces. This has served me well in enterprise code but in writing games in C# I find myself ...
13
votes
7
answers
22k
views
What is a good way to store tilemap data?
I'm developing a 2D platformer with some uni friends. We've based it upon the XNA Platformer Starter Kit which uses .txt files to store the tile map. While this is simple it does not give us enough ...
9
votes
3
answers
6k
views
Is there a simple way to group two or more sprites, so all of them will be dependent on each other?
I think that this question is very similar to this one, but I'm not sure if the answers are universal.
So, my goal is:
Place two sprites in fixed position, for example player and his eyes
Make sure ...
5
votes
2
answers
6k
views
Projectile Aim Prediction with Acceleration
I'm trying to solve the classic shoot moving object problem but with acceleration attached to that changes it from a quadratic to quartic formula but my math skills are not this good sadly as i prefer ...
5
votes
3
answers
35k
views
How do I have a camera follow my object in Unity?
I have an object that automatically moves by itself and I want the main camera to automatically follow it.(Like in games such as geometry dash and jetpack joyride)
This is the code for the automatic ...
2
votes
1
answer
2k
views
Consistent normals at any angle in bezier curve
Could not work out or find any solution for this.
I have a spline which consists of bezier curves (in 3d space) — in fact, any straight line will also have such problem.
I take a point on the curve ...
2
votes
3
answers
3k
views
Pathfinding for units of variable size
I'm using a grid map for a top-down RTS, and I am using the a*
algorithm for pathfinding. Specifically, I've found one implementation which is heavily optimized, and I've been using it for a while, ...
0
votes
2
answers
932
views
How to change LookRotation so the y axis will always face the target position
I have this script that points a missile's z+ axis at its target:
...
59
votes
7
answers
10k
views
What are the dangers of self-teaching game development? [closed]
I am about to embark upon a journey into game development. Following answers to my last question, I will be using C# and XNA.
However, I don't personally know any other game developers and I don't ...
23
votes
6
answers
8k
views
What designs are there for a component based entity system that are user friendly but still flexible?
I've been interested in the component based entity system for a while, and read countless articles on it (The Insomiac games, the pretty standard Evolve Your Hierarchy, the T-Machine, Chronoclast ... ...
17
votes
4
answers
15k
views
How can I acheive a smooth 2D lighting effect?
I'm making a 2D tile based game in XNA.
Currently my lightning looks like this.
How can I get it to look like this?
Instead of each block having its own tint, it has a smooth overlay.
I'm assuming ...
13
votes
7
answers
11k
views
How can I implement hexagonal tilemap picking in XNA?
I have a hexagon tiled map in which I need to check when a hexagon is clicked. The hexagons aren't actually touching, rather they have a slight gap in between each of them.
Does anyone know how could ...
11
votes
5
answers
7k
views
How to properly handle collision in a component-based game?
Trying to wrap my head around the ways to properly handle collision in a game designed around components.
I see many examples have some sort of PhysicsComponent ...
11
votes
2
answers
13k
views
Should I use Async & Await, instead of Coroutines, in Unity?
Should I use Async & Await in Unity? Or should I keep using Coroutines? If I should use Async & Await, how can I do so in a manner comparable to Coroutines?
11
votes
3
answers
4k
views
Isometric Collision Detection
I am having some issues with trying to detect collision of two isometric tile.
I have tried plotting the lines between each point on the tile and then checking for line intercepts however that didn't ...
9
votes
1
answer
47k
views
How do I set the exact local position of a RectTransform?
I have a game object that creates a keyboard in side of my world canvas. I am working out the offset positions for each key, and appear to be doing that correctly. However, when I set the positions in ...
8
votes
2
answers
11k
views
How to determine collision direction between two rectangles?
I am trying to figure out how to determine the direction a collision occurs between two rectangles.
One rectangle does not move. The other rectangle has a velocity in any direction. When a collision ...
8
votes
1
answer
11k
views
How do I compile a C# script at runtime and attach it as a component to a game object
The idea here is to let users program the behaviour of an agent in a way that reminds of the "Screeps" game, where you get to develop code which later runs and dictates the behaviour of your units.
...
7
votes
3
answers
8k
views
Is a custom coordinate system possible in Unity
Is it possible to create a custom coordinate system (i.e the one using double for coordinates or the one dividing the world into 'chunks' of safe size) not ...
7
votes
2
answers
10k
views
How to get mouse position relative to the map?
I'm creating a game in XNA similar to Minecraft - Minecraft 2D
It looks like this
Here's how it works:
All blocks are generated once with fixed x,y coordinates and just re-drawn.
...
6
votes
2
answers
1k
views
Something other than Vertex Welding with Texture Atlas?
What options (in C# with XNA) would there be for texture usage in a procedural generated 3D world made of cubes to increase performance? Yes, it's like Minecraft.
I've been doing a texture atlas and ...
6
votes
1
answer
4k
views
How to chain actions/animations together and delay their execution?
I'm trying to build a simple game with a number of screens - 'TitleScreen', 'LoadingScreen', 'PlayScreen', 'HighScoreScreen' - each of which has it's own draw & update logic methods, sprites, ...
5
votes
1
answer
1k
views
How do I make a jumping dolphin rotate realistically?
I want to program a dolphin that jumps and rotates like a real dolphin. Jumping is not the problem, but I don't know how to make the rotation. At the moment, my dolphin rotates a little weird. But I ...
5
votes
6
answers
3k
views
Making classes available to others
I'm currently working on a 2D game engine in XNA, and I am very interested in architecture, and how best to let my game objects communicate.
I know a lot of people use a Singleton design but I ...
5
votes
3
answers
11k
views
Unity prefab script "GameObjects" can't be ones on the scene?
Currently, I have an object on the scene, and one in prefab. I want the prefab's script to reference to the object on the scene through the
public GameObject obj;
...