New answers tagged c#
4
votes
Accepted
How to clean up list entries when objects are destroyed in Unity?
The best way that I came up with is, according to the observer pattern, to notify all classes where the object was stored about its destruction and remove references to it from there.
That's what I ...
1
vote
Accepted
Best way to implement a carrying tray in VR using Unity
I have found a suitable solution using both Unity's built-in materials and a script that uses a trigger as a parent modifier.
Both the tray's and mug's collider has a material attached that raises ...
2
votes
Best way to implement a carrying tray in VR using Unity
It sounds like you've already figured out the solution:
I'm thinking of some kind of magnet-like system where if you drop an item onto the tray, it becomes stuck until you manually take it off.
From ...
0
votes
Simulate Velocity For A Projectile Moving Along A Spline
I think when a projectile is thrown it should have a burst of speed at the start and begin to rise slower as it reaches its peak height. Then as it starts to fall it should gradually begin to fall ...
-2
votes
Simulate Velocity For A Projectile Moving Along A Spline
Remove the spline and split speed into 2 components X,Y ie Vector2.
Fix a horizontal velocity.X from the spline.
Apply a negative rather large value to velocity.Y, and each step adjusted for delta ...
0
votes
Getting a pixel of Sprite at the cursor position in Unity
This is a super old question, but I was struggling with this for a while, used the code from Savlon's answer and then found it wouldn't work if I moved or scaled the object at all. After hours of ...
4
votes
Accepted
Detect if a key other than "this" key has been pressed
You can first check whether "any" key has been pressed, then check if the key you're listening to has not, to respond only to presses that were not that key.
...
1
vote
Accepted
Converting number in name of gameobject into alpha keycode
If slot is a string then slot[11] is one character of this string and is of type ...
3
votes
Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)
I wonder, do you really need to render noise that is uniquely random down to the pixel?
Or would it be okay if it just appears random?
If you're alright with an approach that relies on staggered ...
1
vote
Accepted
What would be the best way to gradually increase the speed of a 2D arcade game with gravity physics in Unity?
this might not be consistent for different framerates - is that right?
Time.timeScale is independent of framerate. Unity will continue to try to render at the same ...
40
votes
Accepted
Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)
TLDR:
Get DirectBitmap from https://stackoverflow.com/a/34801225 and add
...
17
votes
Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)
When things bog down, check your inner loop. That's the code being run the most often, so even a small inefficiency there stacks up. Here we see:
...
0
votes
Accepted
Flying AI shakes when chasing and avoiding obstacles simultaneously
If I'm understanding correctly, the issue is that you're oscillating back and forth between two states...
State 1 is when you're out of collision range and it moves normally.
State 2 is when it's ...
1
vote
Accepted
How can I instantiate a prefab in a canvas and have it positioned relative to its parent?
The correct solution is to use Instantiate as follows:
...
0
votes
Accepted
Euler Angle X is wrong after using Quaternion.LookRotation
If you want to enforce angular limits, keep it in terms of angles from the start. Don't count on an automatic conversion from quaternions to Euler angles to give you angles in a specific range, ...
0
votes
Euler Angle X is wrong after using Quaternion.LookRotation
If you want to isolate the heading of a look direction then zero out the up and use the atan2 function directly.
...
3
votes
Fast way to calculate angular intervals and occlusion of circular objects in a 2D vision cone
Here are some optimization suggestions:
1. Filter unnecessary tests
Objects located outside the field of view circle(distance>r1+r2) do not need to be detected. ...
1
vote
Fast way to calculate angular intervals and occlusion of circular objects in a 2D vision cone
My first move would be to use a Raycast at regular intervals between the start & end angles. In other words:
begin at the starting angle
perform a raycast ...
Top 50 recent answers are included
Related Tags
c# × 8287unity × 5564
xna × 1399
2d × 467
monogame × 397
collision-detection × 326
physics × 271
xna-4.0 × 260
rotation × 234
movement × 183
camera × 180
3d × 174
mathematics × 165
animation × 151
gui × 148
input × 128
architecture × 110
vector × 107
shaders × 102
sprites × 102
transformation × 101
android × 99
gameobject × 96
raycasting × 94
textures × 92