Update:
Shadows! It looks like the biggest problem I had was with shadows. I had absolutely every mesh giving and receiving shadows. Turning off shadows seems to reduce my issues by 99%. Not sure what the remaining 1% is, but this is way better! So on that note, my question still remains, how the heck could I have known it was shadows? Surely the graph below should have somehow told me this, yes?
Original Question:
The main question is how can I troubleshoot this further? I know there's a profiler thing but I'm not sure what to do with it. Is that what I want and need? Does this tell anyone anything? It should be representative of when the jitter is occurring.
More Background: I use a Vive controller to move by pulling the trigger. I perform a transform based on Time.DeltaTime using the vector position of the controller minus the y axis to know which way to move and how fast. There are tons of enemies and tons of spherical trees. The game seems to run quite well except when I look towards a particular direction. In trying to isolate what it is in that direction, I started turning stuff off such as enemies and the trees. Oddly enough, it makes it WORSE. The only way I can imagine this to be possible is if something is eating up resources all the more now that it's no longer fighting for them with other objects. But it would have to be doing it outside the regular frame loop or else the movement wouldn't appear impaired at all, right? That, or it's something wrong with how I move which now has more processing power to make it worse? I'm so at a loss. Anything wrong with this strategy?
public override void OnTriggerPulled(float triggerPullPercent)
{
if (!mainHand && triggerPullPercent > 0.05)
{
Vector3 goForward = transform.forward;
goForward.y = 0;
transform.parent.transform.Translate(goForward * triggerPullPercent * Time.deltaTime * 5f);
}
}
Even worse, the issue is inconsistent. After removing all the trees and seeing zero signs of improvement, I removed a single object just cuz it was ugly and not ready for the game anyway. Suddenly, things seemed quite a bit better than the "Worse" state it was in but it was more akin to the original jittery state which had me doing this to begin with. I added the object back in and oddly enough, it did not revert back to its worse state. So clearly it must not have been the object that made it any better/worse. I added my trees back in and it was suddenly back to the horrendous state. Now suspecting the trees, I removed them again and found no difference. Still crappy. So... not the trees or the object? I removed the one object and it was suddenly much better again. I can do this forever very repeatably. What gives? It's neither and both simultaneously? Any ideas? What more can I do to troubleshoot this? My current method is severely lacking.
Thanks!
Related
So let me preface this that, i am very new to unity this is my first week actually lol and i couldnt exactly find anything that would answer my question.
Anyways, i have this like thwomp object that has 3 animation states crush, reset, and wait. and it goes up and down as you would see it normally just on a timer because of the wait. it is done by adding the position property and then moving the y up and down. pretty simple i think, couldnt think of anything better. it works perfectly just like i want it too.
but when i made it a prefab and try to make more of them, the animation for the copies have the same x and y as the original. so like even though i can change the base like default positioning of them whenever the game starts and the animation plays they just perfectly overlap with the first original one that the prefab was made with. when i try to change the x coordinate on the copies animation it updates the x coordinates for all them. this happens even when i delete the prefab and just manually make copies with ctrl + d as well (im not sure if this any different?) . i assume this is because they all share the same 3 animations so when you change the animation it changes it for all them and that makes sense.
but i really dont want to make 3 seperate animations for each replica thwomp i make, i feel like there definitely has to be a better way. my original thought of how it would be was they would share the same animation, but like within the object its self the animation values like the position are exclusive to the object so they could differ inbetween each one.
ill include a link a picture to like further convey what i have going on here so its easier to understand. https://imgur.com/a/78q6VCI
You want to change the localPosition not the world position. This thread has a little discussion about it but basically you need to use the x, y, z you get from the Animator as an offset to localPosition.
Pseudo code:
transform.localPosition.y += animators position.y
https://forum.unity.com/threads/playing-animation-local-to-position-in-unity.53832/#post-489101
Special note: Using an animator is pretty heavy. For simple stuff like this I would suggest just scripting it.
I am making an FPS game and I need for the forward facing vector to hit exactly where the crosshair is aiming.
This is my current blueprint.
It takes all references from the camera position where the players head should be. (as it usually is in FPS games).
When "shooting" the vector it is slightly offset though. (pink dot near crosshair)
Things I have tried:
Increasing distance of vector makes the problem go away but it then becomes inconsistent, which means it's a bad solution to the problem :(
Manually changing axis values, but that was also very inconsistent.
Changing between 3 different nodes of taking rotation from the camera, they all (didn't) work the same way :/
Maybe there is an issue of the values that I am taking, although the starting position of the camera seems to be correct.
Thank you for any insight you may have!
Suggested by user Ruzihm the issue was that the crosshair was off-center. My blueprints were actually okay.
So for anyone looking see if your crosshair is in the center.
So I am kinda stuck on what to do now because as I said I am trying to use Rigidbody.AddTorque to rotate a rigid body towards a certain point, which I was going to use to align a player with a gravitational pull so they can be upright. I have got the input part of the code, I just don't have a way to rotate the player to align with it, without violating the laws of physics with Quaternion.FromToRotation and messing with my character controller too, which I am trying to make entirely physics based rotation wise too to avoid any other problems.
I have experimented with a couple of methods, first I tried adapting my character controller code which used Rigidbody.AddForce to move the player and also dampening unwanted movements, as Rigidbody.AddTorque is basically Rigidbody.AddForce but for rotations, however, it was too weak and just flopping around when I tried it, here's the code for the character controller for calculating the force needed for one axes:
if(projected_speed.x*speed == relative_v.x)
{
applied_speed.x = 0f;
}
else if(Mathf.Sign(projected_speed.x)== -1)
{
applied_speed.x = relative_v.x - Mathf.Abs(projected_speed.x*speed);
}
else if (Mathf.Sign(projected_speed.x) == 1)
{
applied_speed.x = projected_speed.x*speed - relative_v.x;
}
Where projected_speed is the speed the controller wants to be at,relative_v is the relative velocity, and applied_speed is the speed that will be actually applied in Rigidbody.AddForce.
Anyways so maybe I didn't use enough force, as the player is under a gravitational pull, but that would have probably made it flip out or something, anyways so the second thing I tried was a PID controller, and I managed to find a page which explains it pretty well, sadly don't have the link anymore, but when I tried this because you have to tune it, I was stuck doing it, and it just wasn't able to do anything and was just rolling around the floor and sometimes spinning, probably as it couldn't cope with gravity, so that didn't work, so does anyone know how I could finally do this and make my character able to right themselves according to gravity?
Sorry for not indicating that my issue is solved, click here for the answer, credit to Ruzihm.
When I was missing around with Unity once, I encountered a problem where the main player's position start losing precision, wobbling and
movement smoothness turns into jitter.
It turns out I was going too far off the origin point which is too much for unity's vector3 floating point to handle.
In graphic. You can easily overcome this issue by just looping through a certain range. Ignoring that will result in an issue similar to this:
Source: https://youtu.be/wGhBjMcY2YQ
Which makes me really wounder, how do developers over come finite variables to create infinite worlds. I personally haven't dipped my toes in making infinite world but I have encountered the graphic floating point error.
If developers relay on the fact that players will never reach the point where that error start to occur then technically, it's not an infinite world.
I would love to hear from the experts.
as most of you might know, the default character controller settings in unity allow you to simply jump up any mountain / hill, even if its more than the slope limit. Granted you can't WALK up it, but you can still jump up it while moving forwards.
In an attempt to fix this, I used the code from another answer:
void OnControllerColliderHit(ControllerColliderHit hit)
{
float radian = cont.slopeLimit * Mathf.Deg2Rad;
if (hit.normal.y <= radian)
{
canJump = false;
} else
{
canJump = true;
}
}
and in my update function I only jump if canJump is true (as you might have guessed)
So it almost works as expected, when the player approaches slopes that are beyond the slope limit (I THINK at least, if my radians calculation was correct, 'cause I don't really get what hit.normal.y is, if that's the same as the slope limit or not, so I kind of guessed... if anyone can correct me on that, that would help.)
Anyway, first of all I need to fix that fact that the character can't jump even when he's facing AWAY from the mountain, I don't know how to calculate if he's FACING the steep slope or not, only if he's colliding with it, so if anyone can help with that, that would be good, and (related):
I also can't figure out how to stop the player from jumping on these steep slopes from far away and staying on them, if he jumps on them or ends up on them however, he should simply slide down the mountain until he's on a regular slope, but I have no idea ow to get the CharacterContrller to slide down things, and especially not only until he reaches a regular slope?
Also it seems like this also applies (the fact taht he can't jump) to when the character is walking up stairs sometimes, but that's a big no-no 'cause he should always be able to jump up stairs if they're reasonably small enough, but I don't know how to differentiate between a terrain object and stairs...
If anyone can at least answer one of these three issues, that would be great (but prefereably all of them 'cause it's all part of the same question: How to just get normal character sliding / jumping regarding slpoes and stuff! (even though that wasn't the official title)