I'm using the FadeObjectInOut script from the wiki (http://wiki.unity3d.com/index.php/FadeObjectInOut)
It's attached to two different objects (each), which trigger indiviudally. It'll resolve in
IndexOutOfRangeException: Array index is out of range.
FadeObjectIO.SetNewColor (UnityEngine.Renderer[] rendererObjects, Int32 i) (at Assets/Scripts/FadeObjectIO.cs:132)
It reffers to the line
Color newColor = (colors != null ? colors[i] : rendererObjects[i].material.color);
..., which tried to export as an function and still calls the same error. The whole code snippet relies on IEnumerator.
Due to the fact, that this only happens every now and then, I'm totally confused. I can't provoke it by triggering the events at the same time, I can't provok it by flashing between fadeOut and unIn super fast.
As solution, I tried things from the internet and also the "How to Avoid" of this question: What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
The last time, I triggered my oculus trigger on/off in high frequency and nothing happend. Frustrated I wanted to take the headset off and as I put down my controllers, it crashed again. (It's on the Touch trigger and thereby easily fast triggerable.)
I can't help myself anymore...
Thanks for any advise
.
EDIT: below the thrown error + the debug code. After fading out, the Renderers are getting enabled=false.
Since we are in a while loop, it doesnt really make sense to me tho, that the dot might've been already faded out (and it's renderer therby deactivated) being an error for the array - because it doesnt get any changes. Hmmmm.
Debug everything
Edit: new state
Related
Here's a screenshot of what it looks like when the error occurs
So in my marble rolling game, sometimes when the player (the Sphere) collides too hard with another object the game freezes and the Error message fills my error message box instantly.
I tried looking up exactly what the error meant, but to no avail so if anyone knows where to find such information please point me in the right direction :)
I'd rather not implement a max speed as that kind of takes away from the fun of the game since speed controll will be a big part of it.
The literal meaning of the error is that the absolute value of whatever det is, isn't superior as whatever FLT_MIN is in the unity system code.
You might want to take a look at this thread.
https://forum.unity.com/threads/unityengine-guiutility-processevent-int32-intptr.514797/#post-6935341
or this one
https://forum.unity.com/threads/assertion-failed-on-expression-std-abs-flt_min.883201/
I'm using Physics2D.BoxCast in Unity(2019.4.19f1).
I have a collider2D at position==(0,0) with scale==(1,1)
Then I call a Physics2D.BoxCast:
var hit = Physics2D.BoxCast(new Vector2(0, 2), new Vector2(1, 1), 0, new Vector2(0, -1));
It is a Box Ray Cast like the following pic:
I have a hit returned.
But hit.distance == 0.9950001, which is supposed to be 1.
I guess there may be some inaccuracy in Physics2D.BoxCast. But I have no idea how much the inaccuracy can be.
Then I do some searching and find "Default Contact Offset" may be related to my problem.
I change "Project Setting → Physics2D → Default Contact Offset" to 0.001(default is 0.01).
Run the code again. But now I get hit.collider == null.
Now I'm more confused about Physics2D.BoxCast.
It may be helpful to learn something about how Physics2D.BoxCast work. But I do not know where to find them.
Added 2021.3.1
I did several experiments about "DefaultContactOffset".(link)
The experiment results show that:
If the DefaultContactOffset is about 0.002~0.01. Most of the time, the error in hit.distance is about 0.005.
If the DefaultContactOffset is about 0.02~0.1. The error in hit.distance is larger.
I actually don't know Physics2D.BoxCast but from what i understand it just moves a box to your target at a "speed". Now I done similar calculations in opengl and any collision like this using a speed over time will result this behavior. You can't expect to get a result %100 accurate. imagine every frame you move the red box 5 points instead of a small scale. You red box would just jump over the white box and you would not get a hit result..
Now internet says " Reducing Default Contact Offset can mean that collisions don't have enough of a buffer to work correctly. " so i guess Physics2D.BoxCast just check if 2 objects is going to collide and not if they are colliding which would explain why you get a null hit when you make the ofset so small.
Edit:This was a comment but was too long.
Afternoon, Recently while trying to develop the more; Err Graphical part of my 'Editor Extension', Through towards unity3d's Audience I've been looking at creating more of a dynamic window for screen sizes!
Throughout my testing I've noticed many hard-core glitches that I cannot seem to persuade, Currently I've tried "doubles, int, float, etc.. etc..", Though my issue might just be with unity, I'm sure someone here has had this event occur while attempting to scale their "Editor Application", Here are some visual representations of the variable issues i've been having.
Error && Success Image Collection!
Upon my Journey of Dynamic Screen Fitting Here is some of my current attempted code that I have within my project for the window as of now.
private Rect Topic_Selection_Rect_Window = new Rect(5, 5, Screen.width / 6, 350);
static void Init()
{
EditorWindow Toolbox = GetWindowWithRect(typeof(Toolbox), new Rect(0, 0, 1250, 900));
Toolbox.Show();
}
private void OnGUI()
{
BeginWindows();
GUILayout.Window(0, Topic_Selection_Rect_Window, Topic, "Please Select A Listed Topic!");
EndWindows();
}
private void Topic(int id)
{
GUILayout.TextField("pre-text");
}
Now with the code shown above, We Have on the "Price rect topic_selection_rect_window", We have the idea that 'Oh, we can just use the API for 'Screen.width', Though initially i've noticed that the idea of that is knowing the users screen - information, Though the reality of it is I'm thinking that initally it's all wonky for inital load to get user-information which I need to entail an idea on how to attempt to get that upon init, Though i've tried hasn't seemed to work accordingly, Though once I load and it's all wonky and I exit and load again it's less wonky and one last time and it's fine; I've had some issues for some time such as "Screen.height" never seems to work and give me a good ## or Screen %% availability and just tends to not work with my monitor or what; I'm fairly new to programming and I'm looking to figure out how this API works, etc thanks for any
comments / answers!
-- DrEncompass --
After-Hours of tinkering, I'd have given up while messing around I later had an issue with my window not being able to have de-bugging and I had to re-boot Unity3d Every-time I had crashed my Editor-Window, So after some messing around I figured I could just directly call the window with the [.show();], And so far it's appearing to be a strong solution!
I am creating a 3D gravity simulation in Unity. I have everything working correctly except the collision response. I want to make collision resolve calculations from the exact point of impact rather than the time of the current timestep. I have looked around, and I think I have found the correct equation to determine the exact time of collision. However, whenever I try to execute the code, I am getting a NaN error as a result. I have tried everything I can think of to fix the issue, but nothing seems to remedy the error. Can someone take a look at my code and see if you can identify any obvious errors I may have missed?
The method I am having trouble with was designed to determine the exact time of impact between two spheres which I know have collide within the last timestep. If each timestep is 1, the method is meant to return a number between 0(the current timestep) and 1(the previous timestep) that the collision occurred.
This is the formula I am using
Vector3 velocity2MinusVelocity1 = particle2.GetComponent<Particle>().Velocity - particle1.GetComponent<Particle>().Velocity;
Vector3 separationVector = particle1.transform.position - particle2.transform.position;
return ((-(Vector3.Dot(separationVector, velocity2MinusVelocity1)
/ (Mathf.Pow(Vector3.Magnitude(velocity2MinusVelocity1), 2))))
-
(Mathf.Sqrt(
Mathf.Pow(
Vector3.Dot(separationVector, velocity2MinusVelocity1)
/ Mathf.Pow(Vector3.Magnitude(velocity2MinusVelocity1), 2)
, 2)
-
Mathf.Pow(Vector3.Magnitude(separationVector), 2)
- Mathf.Pow(particle1.GetComponent<Particle>().Radius
+ particle2.GetComponent<Particle>().Radius
,2)
/ Mathf.Pow(Vector3.Magnitude(velocity2MinusVelocity1), 2)
)));
I apologize if the structure is a little hard to follow. I tried to make it as easily readable as possible
I'm trying to move a body:
if (ks.IsKeyDown(Keys.Up)) {
rocket.ApplyImpulse(new Box2DX.Common.Vec2(0, 30f), rocket.GetPosition());
}
Oddly, the body only moves when the key is released. Why is this? I've been looking at the manual but can't figure it out.
When I remove the conditional, and just have the applyImpulse() call in Step(), the rocket continually has the animation of thrusters but never actually moves. (As if I had been holding down the Up key the entire time.)
Looks like what I really need to get this working is a better understanding of what the first argument to applyImpulse() does:
new Box2DX.Common.Vec2(0, 30f)
What is the significance of the two values in the vector?
UPDATE This works much better:
rocket.ApplyImpulse(new Box2DX.Common.Vec2(0, -1), rocket.GetPosition());
It looks like if the second value in the force vector is negative, the object rises on the screen. Before, the impulse applied was just slamming it into the floor. When I released the key, it would sometimes bounce back, if the impulse had been strong enough.
Regarding your update: In XNA, depending on how you've situated your camera, negative Y is up. If you want the rocket to go up, you have to apply a force in that direction.
That makes no sense as to why it only moves when it's released, is there nothing else interfering with it elsewhere such as another keyboard input hidden somewhere? I only ask as it could be that another keyboard input statement in conflicting with another and causing the problem.