As the image shows, two box colliders(2D) stay close together, while a circle collider(2D) fall on the common border.
I hope it will bounce forward (blue arrow), but sometimes it bounce back (green arrow).
I have checked the position and the width, and have make sure the box colliders(2D) are touch to each other perfectly.
(positions: (0,0), (2,0), widths: 2, 2)
I am new on Unity, and have no idea how to prevent the strange bounce.
Please give me some help, thanks.
Image
Maybe It'll work if you edit the colliders like this:
I am not quite sure what is the problem, I hope this helps.
Related
As you can see in my Unity scene
it looks dark.
game tab
you can see here that it's dark.
I've done going to window > render > lightning > clear baked data but its still the same.
Any unity devs can help me, thanks
As you can see in my lightning tab
auto generate is disabled so I can't check it to verify if it can solve my problem.
Somewhere in the Canvas you have an object that has a sprite on it where the color is modified. Also check the alpha setting for the colors there.
Lighting doesn't affect UI elements like that. That only applies to non UIElements like 3D and 2D objects placed in the world (https://docs.unity3d.com/Manual/LightingInUnity.html).
So it's just a sprite that is causing this background color as #Çağatay IŞIK suggested.
The image with the compass and other UI is actually the top left corner and the tooltip is spawning outside the canvas as you can see.
Ive been searching for hours now on how to fix this:
Im using a Screen Space - Overlay Canvas.
Setting an UI Elements Anchored position through code to make it follow the mouse.
Vector2 anchoredPosition = Input.mousePosition;
rectTransform.anchoredPosition = anchoredPosition;
However this doesnt retun the right position.
I tried Input.mousePosition / Canvas.scaleFactor;
And I also tried Input.mousePosition / canvasRectTransform.localScale.x;
And finally Camera.main.ScreenToViewportPoint(Input.mousePosition);
But again, no luck at all... Free Aspect doesnt fix it either.
Changing the reference width and height doesnt fix it, setting from 16:9 to 16:10 does nothing to help me either.
The UI element is always way outside the actual canvas (camera view).
The UI element itself is a RectTransform with size of 1,1 with the anchor in the middle. Testing it by setting element position to 0,0 shows it perfectly centered.
Can someone please help me?
Thank you.
EDIT:
I got it to work by changing the reference resolution on the Canvas until I saw the canvas scale was exactly 1,1,1. Ofcourse I dont want this reference resolution, but atleast it tells us that it has to do with that:
Mouse position is read on screen coordinates. Canvas position is a combination of the canvas reference resolution, your actual screen size, and the canvas’ scale factor.
Say your screen is 1080p and your canvas reference resolution is 1080p. And the canvas is set to fill your screen. The coordinates will directly line up between mouse position and canvas position.
With different screen resolutions than the reference resolution, this Gets more complex to calculate. But there’s a handy function to handle this for you.
RectTransformUtility.ScreenPointToLocalPointInRectangle
https://docs.unity3d.com/ScriptReference/RectTransformUtility.ScreenPointToLocalPointInRectangle.html
I have a game in Unity.
The idea of the game is that an object is spawned on the screen.
It exists for several seconds.
You need to click on it, while it exists.
What I want to do, is that while it exists - I want to show a timer, but not with numbers, but with an outlined line on the perimeter of the screen.
I know, how to make a make a slider and how to make circular health bar, yet I do not really have an idea to make a slider, that is decresing from everywhere to the centre as you can see on the screenshots below.
I would be thankful for the inspiration!
This should be a very good fit using alpha cutoff with a custom shader.
Here's a video explaining it in detail (it's only the first half you will need).
The basic idea is to create a texture with a graded alpha depending on how you want the texture to appear/disappear. In this case the alpha value at the top and the bottom would be close to 0 and then gradually around the line on both sides towards the middle increase to 1. The shader then cuts off the texture below a cutoff threshold which you can change depending on the value of the timer.
As a dumb and simple approach:
Have two images with fill, one goes middle towards top the other middle towards bottom.
Just imagine the pnguin is your outline ^^
I'm doing a Unity project where I basically have a Directional Light rotating around the map, starting on 0 to 360 degrees.
However, when it gets dark = rotation from 100 to 120 degrees I get this strange blue light coming from the sky, does anybody have any idea on how to avoid this blue thing appearing?
Image to explain the problem
It seems to be a Lens Flare. Check if you have "Flare Layer" on your Main Camera and disable it.
https://docs.unity3d.com/Manual/class-FlareLayer.html
https://docs.unity3d.com/Manual/visual-effects-lens-flares.html
You can try as follows:
Find the little blue dot step by step and delete it. First click on the point light source in the scene, find Light->Flare, as shown below
Click 50mm Zoom to find it in the project view and see its detailed properties in the Inspector. As shown below.
Click on the elements, you can find that it has 19 elements, expand each element, and find that the color of one element is blue. As shown below:
That's it. Set the size to 0 and the problem is solved.
Thank you, hope it helps you
I made a game where the player controls a square, whenever it hits a wall it is supposed to die. The Square is a Picture Box and the walls are picture boxes too. You can move using W,A,S and D. I was thinking about doing something similar to:
if(Square.Top == Square.Top + Square.Height)
and then restart the game. Is there any better way doing it? Istead of having alot of IFs? Whenever a control touches another to do something?
Thanks alot !
Yes, you get the control's containing rectangle by Control.Bounds, and then use IntersectsWith with another rectangle.
if(Square.Bounds.IntersectsWith(Wall.Bounds))
{
// ...
}
Keep in mind that it won't trigger when your square touches a wall, only when it starts going on top of it, but I assume that's what you want.