Skip to main content

Questions tagged [c#]

C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.

Filter by
Sorted by
Tagged with
0 votes
1 answer
15 views

2D drag and drop dynamic rigid body spinning out of control in Unity

I'm trying to make a 2d game that involves dragging and dropping certain dynamic physics objects (like squares) and I am a beginner. I need it to look like the rest of the object holds a weight when ...
0 votes
0 answers
37 views

FirebaseReference.GetValueAsync() in Unity Not Completing

I'm working on a Unity project where I use Firebase to manage user data. I am encountering a recurring issue where the asynchronous task GetValueAsync() does not ...
0 votes
0 answers
37 views

I am trying to move a sphere along a curved path made using spline. The problem i am facing is that the ball's velocity when i apply torque is less

I am trying to move a ball along a curved path using torque on the rigid body. The problem that I am facing is that the ball's velocity when I am applying torque is really less, it moves really slowly ...
0 votes
1 answer
27 views

Weird behaviour with SpriteBatch.Draw in MonoGame

I'm creating a rhythm game. I'm trying to move automatically Notes from upside but something went wrong. Notes just stuck. Below is code, thanks in advance for help because I don't understand what I'...
0 votes
0 answers
46 views

Why do I have to freeze my player's x and z rotation to make my player movement work and why does my camera stutter when colliding with things?

So I have an empty object called player with the PlayerMovement script and a rigidbody. I have the main camera and player visual as childs of it. The movement works ...
0 votes
0 answers
31 views

RigidBody floating in th air

I added a death animation among some other things in case of death. But after playing it the player is airborne, so I might need to change the pivot. But I'm wondering if this can't be done with some ...
0 votes
0 answers
25 views

How can I check if the rigidbody is moving

The problem is that rb.velocity probably returns too small values ...
0 votes
1 answer
37 views

Tilemap.SetTile results in no visible change in build

I have an issue with how the Tilemap works in build, using version 2022.3. I update my Tilemap with Tilemap.SetTile(Vector3Int pos, null) and it works just fine in ...
3 votes
2 answers
918 views

Efficient 2D grid overlay on tiles without each cell being its own GameObject

So for my game I need the ability to add a grid overlay over my tilemap. Now I don't think that making the grid with each cell being its own GameObject with some SpriteRenderer would be hard to do but ...
0 votes
2 answers
62 views

Normalize an angle in unity

How can I normalize angle between min value and max value? like normalizing -1136316.78186234° between 0° , 360° or between 180° , 360°. Node: for now I'm using double value as angle. Thanks for ...
3 votes
1 answer
655 views

Create context menu in Scene view

I created some MenuItemfunctions for navigating, which are currently displayed on the menu toolbar. The C# code: ...
1 vote
3 answers
2k views

Instantiated object not tracking collision

I have an issue, and I'm not sure why it's happening. I have a prefab that I've built in a colour-changing game. It has the following: Four 2D objects that if they collide with the player (2D ...
1 vote
1 answer
74 views

Octree as struct not class

I was wondering (as I could not find any implementation online), if anyone here would have an idea of how to create an octree as a struct and not a class. The problem is that Octrees are usually ...
2 votes
1 answer
26 views

Deleting components via OnValidate script while in editor

I want to create different types of platforms for my game, and they are currently all in different prefabs. This works fine, but it is just taking so long to search for the prefab, dragging it in, and ...
0 votes
0 answers
45 views

Rotating Towards the Anchor Point while Swinging

So I've been working on a Spider-Man like game for my company and I need some help with the web-swinging. Specifically, rotating in the character in the direction of the anchor point so the swinging ...
0 votes
1 answer
766 views

How can I create a pressure pad in order to open a door?

I'm making a 2D platformer with Unity and I'm trying to create a pressure pad to open a door. I want the door to open when the player is on the pressure pad and close a few seconds after the player ...
0 votes
0 answers
42 views

Issue when making the player face the direction it's currently going

I'm trying to make the player face the direction it is going, not facing up & down but only on the X & Z axis. Currently the player keeps facing only one direction, no matter which direction I'...
0 votes
0 answers
14 views

How to implement 3rd person animation with acceleration from walk to run?

I am new to Unity and I am using dr Penny de Byl's lectures on Unity. I am trying to use a Mixamo character. I downloaded a character with skin as an fbx file, and also added some character movement ...
0 votes
1 answer
35 views

Weird behaviors with transform.LookRotation when looking at position+Vector3

I'm working on a character controller for an isometric retro shooter. However, when making the character rotate towards where they are moving, I encountered some issues. The character doesn't fully ...
1 vote
4 answers
5k views

Tab between input fields

I am new to working with Unity3d, I need to navigate between several inputField, for this I have looked at the solution that is in: tab-between-input-fields, but ...
0 votes
1 answer
599 views

Calculating position to position B with speed

I am trying to find out a formula that calculates the actual position of a player using his speed and a destination position. These are the informations I have: Vector3 (X,Y,Z) : Current position ...
1 vote
1 answer
93 views

How to generate a series of checkpoints randomly along a 2D line

I was wondering how I would go about generating a series of checkpoint gates along a 2D line in my game. A bit of background, my game is a 2D reinforcement learning car driving simulator, I have a ...
0 votes
1 answer
485 views

How to get reference to board tile object another game object is sitting on?

I am trying to get reference of the object underneath my Player. I don't know if I am approaching this correctly. Right now, I have a player simply put in the scene, like this: Then I am trying to ...
1 vote
1 answer
63 views

What is the simplest way to enforce/remind people to set a variable in a subclass when the code is dynamic?

I have a base class for Abilities. This is a point and click game, therefore I have Click, Hold and Drag subclasses. What I need to do is remind myself to set the player's AI state to Ability when it ...
0 votes
0 answers
29 views

Inconsistent results from ApplyCentralImpulse with RigidBody2D

I'm working on a 2D top-down game using RigidBody2D for the player and enemies. They're bouncing and moving (using ApplyCentralForce) and detecting collisions just fine, however now I want to add a ...
6 votes
2 answers
586 views

Collision detection problem in XNA4/Monogame

I have been trying to get 3D collision detection working for a while and I think (hope) you people can help me. For my project I have created a 'sprite3d' kinda class which is called ...
0 votes
1 answer
636 views

How to check if one object's local bounding box contains another

I am currently trying to check whether the first object contains a second. I first tried to use the bounding box, but it is defined in world space, so it is not working with my rotated cubes. Then I ...
0 votes
1 answer
48 views

Call to Random.Range() is breaking my prefab instantiation

This is for a simple sidescrolling game. I want to have it so that when an enemy is killed, it has a chance of dropping a health collectible for the player. I wrote a separate simple bool method ...
1 vote
1 answer
68 views

Rotating around Wall Corners while Climbing

So I've posted here before regarding a Spider-Man like game that I'm working on. I'm facing another dilemma now. I want to rotate the player around the edges of walls. So far, I've implemented a ...
2 votes
1 answer
473 views

Trouble GamePad input on iOS but works perfect on Android

I am having trouble getting input from on iOS devices (iPhone 6 Plus and iPad). Here is my code, ...
0 votes
2 answers
55 views

Getting the Player to Face Movement Input on the Z-axis

I'm working on a Spider-Man like game and I've run into a problem. Whenever I'm near a wall and press the w key, the player starts climbing the wall. But when on the wall, I want it to face the ...
0 votes
0 answers
13 views

How to use a key to stop playing the current animation, and replay it from the beginning?

In my Unity project, I tried to use a key to stop the current animation and immediately play it from the beginning again. I also tried to control the delay before I can press again. The following ...
0 votes
2 answers
483 views

How to set GameObject on tilemap through script

In the built in Tile Palette tilemap editor, you can choose a GameObject brush to set custom tile GameObjects. How would I be able to set a gameObject onto a tile through a script?. There is no ...
0 votes
2 answers
49 views

Can you somehow use underscore to ignore different results in Unity like you would do with TryParse?

So I may not be the best programmer, but I am not a beginner. So in C# when you want to check if... lets say if its a number or not, but you dont care about the result(the you could write something ...
4 votes
3 answers
6k views

Flip sprite vertically AND horizontally?

In Microsoft.Xna.Framework.Graphics.SpriteEffects there is the possibility to flip a texture horizontally or vertically before rendering. But can one do both at the ...
0 votes
2 answers
477 views

Converting from global coordinates to local coordinates

I am trying to create a Radar/Minimap for the F1 2021 game in C#/WPF. Here is a image of what I am trying to replicate In the image, the white car (my car) will always face the direction it is going. ...
0 votes
1 answer
410 views

Marching cube terrain generated by compute shader gives strange error

I'm creating my own terrain terrain system for Unity using marching cubes but I've run into a problem I'm stumped on. First I'll explain how it works: A compute shader creates an array of points ...
0 votes
2 answers
117 views

Is this enough calculation on server-side to be secure?

I'm a beginner about client/server calculations and relationships (never trust the client), and I would like to know if I did or didn't get the concept right. My weapons are calling this function ...
2 votes
2 answers
61 views

How would I make minimap of racing track where dot follows track progress in Unity?

I would like to show race progress in my UI. My minimap is like sketch below: Blue dot represents progress and red dot is finish line. I would like this to work in UI so only blue dot would move. If ...
0 votes
1 answer
33 views

I am having error CS2012 when trying to run my visual studio code in unity (i am new to this)

I made my first script in Visual Studio and saved it to Unity, however, i get this error: The requested operation cannot be performed on a file with a user-mapped section open. This is my code: ...
0 votes
1 answer
31 views

Null reference exception when adding bodies to a list

So, for conversational clarity/brevity, I have 3 sphere gameobjects, each with their own Rigidbody component. They all have a tag of 'body'. The 3 spheres have progressively larger masses. body1 mass:...
0 votes
2 answers
7k views

Diagonal movement is faster than horizontal or vertical movement. How to fix?

When using Horizontal or Vertical input keys, the the movement is normal. But when trying to move diagonal, multiple keys are to be pressed, and the speed just stacks up. Yes there are many answers ...
1 vote
1 answer
4k views

Issues using NetworkServer.Spawn with Unity and Mirror-Networking

I am using Mirror to handle the networking aspect When I spawn an object on the network, I Instantiate it on the server and then use NetworkServer.Spawn to notify all clients to spawn the object. ...
1 vote
0 answers
60 views

Cheap 2D fluid simulation at low resolution

I have a 64x64 display and an accelerometer. I want to run a 2D fluid simulation and take a reading from the accelerometer as the gravity vector. I'm going to be doing this on fairly low-end hardware (...
0 votes
1 answer
1k views

Floating Boat 3D Physics Rotation from Rudder (no water resistance)

I have been able to simulate a floating boat very simply by attaching a script called Boat.cs to a ship model with a Rigidbody; ...
0 votes
1 answer
74 views

Checking combat on the server to prevent cheating - how to keep two codebases in sync?

I'm making an idle game with semi-multiplayer. My game uses Unity as a client and as a server Unity Gaming Services (UGS) C# Cloud Code Modules with UGS Cloud Save, this server is non-persistent, ...
2 votes
2 answers
1k views

Unity is reseting Dictionary when game is playing

I have a class named Item, I am storing instances of this class in list. List is created before game starts, everything works fine in that moment but when I am playing, items still are in list but ...
0 votes
3 answers
1k views

Camera Jitters When Displacing and Rotating Smoothly

DISCLAIMER: I am using Unity 5.6.5f1 for this code, I honestly don't know if there would be API updates on later versions, though I don't think so. I tried to make a simple Third Person Camera that ...
0 votes
0 answers
16 views

BehaviourDesigner Runtime Squads for new Formations

I'm struggling to make a new "Squad" at runtime from group selection to move in BehaviourDesigners Formations. The code for what I've done but this would turn this question into a novel, so.....
0 votes
1 answer
74 views

Unity: Cannot access TMP_Text object from script in gameobject

I'm trying to set the color property of a TMP_Text object but keep getting Object reference not set to instance of an object error. Setup is as follows; I have a ...

1
2 3 4 5
168