New answers tagged

0

As per the comments it doesn't look possible to mix input systems together. I will use the answer given by IQew and use plain Image UI Element to interact with the mouse, drag the object and then, when it is in game I will switch it to sprite , either by destroying the gameObject with the image attached and creating a new Sprite in place, or just toggling ...


0

In order to get the particles behind UI elements you have to change the "Order in Layer" for either the canvas for the UI elements, the VFX Layer or both depending on what's best for your project right now. Create a new project and try this: Set the camera to orthographic and give it a reasonable size for your target resolution Create an Image in the scene ...


0

first, welcome to this community. second, before making any real project try to read all of its documents and do some tests with it. on canvas select scale with screen size and drag anchors to fill the place you want. so your object scales to fill in different phone screen sizes and ratios. about particles and obstacles, it depends what tools are you ...


1

If you need the Image enabled during the process but also do not want it to 'receive input' you can get a reference to the image and disable the Raycast Target. Then re-enable it when you need it. If you never want it to be selectable you can just uncheck the box in the bottom right. image.raycastTarget = false;


0

Your use-case is two-fold: Projecting your 2d mouse coordinates to 3d world coordinates, to create a ray. Performing collision detection on the new coordinates, compared to your game objects. NDC to 3D world coordinates To do this, you need your view and projection transform matrices: mat4 view = lookat(camPos, camPos+camDir, vec3(0.0f,1.0f,0.0f); // For ...


1

Do your entities both use box colliders? When two axis-aligned box colliders collide, then there isn't really a single collision point but rather a collision line on which the colliders touch. Unity is supposed to return multiple collision points in such a situation. That's why Collision2d.contacts is an array and not a single value. But your code only ...


0

I'd probably use those three variables: Vector2i previousTile Vector2i nextTile float transition Previous and next tile are pretty self explainatory. If player wants to move, nextTile is set to his target coordinates (eg. [2, 1]). Player is in "moving" state if previous and nextTile are different. The "transition" field is used to tell where the player is ...


0

Since you wanted an agnostic answer, This answer will deal with how to integrate this in any 2D game framework. You have supplied orthographic projection models. What you can do is, say, you have an origin for each of those models, and each pixel on the model itself will correspond to a depth value based on that offset. Blender apparently allows the z ...


0

I share some code which will help you out: public float force = 5; public ForceMode forceMode = ForceMode.Impulse; private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Enemy")) { Debug.Log("Collision"); health -= 20; //Check for death if (health <= 0) { ...


0

The HTML5 Canvas simply creates a rectangle in the screen, where you can draw custom graphics. It is usually preferred for games, because of the need to draw a lot of different elements, with complex animations. Should I actually be using an HTML5 < canvas > element for this task? In programming, usually there is no should. Can you make it work with ...


-2

In Unity this would be very easy to do that, but my question is, do you have actual 3d models? if yes, than you can go for orthographic projection and do what you want to do. No need to worry about the depth or masking. Even if you don't have 3d models, i would waste time in creating simple models and when everything will start working fine, than i will ...


0

try smoothing it out a bit with something like Vector3.SmoothDamp() public Transform target; float damping = .05f; float followDistance = 2; private Vector3 currentVelocity; private void Update() { if (target != null && Vector3.Distance(transform.position, target.position) > followDistance) { Vector3 newPos = Vector3.SmoothDamp(...


2

Usually the way we handle this is to introduce a new move that's a "slash precursor" whose short ~2-frame animation reads plausibly as the lead-in for either a horizontal or vertical slash. When the button is pressed without the up button held, we immediately start the slash precursor move. If the up button is pressed while we're in the slash precursor, we ...


0

Collider boundaries extents do not scale with the Transform. The GameObject / MeshRenderer's role is to give a visual shape to your object while the Collider's role is to give it a physical shape in the Physics world. If one aspect (either visual or physical) changes it doesn't have an impact on the other one. I agree that the fact the Collider automatically ...


0

2D math translates in game programming to 2D transformations. What to implement? Rotations, scaling, 2D shapes overlap/contain tests. Only with that you can already code a lot of fun games. With the correct terminology you can easily search for the required techniques. I included a single link as an example. While the above paragraph tries to answer the ...


0

It sounds like you're dealing with foreshortening. When you look down at the z-axis along a diagonal, only part of the length of a z-pointing vector goes into climbing your screen. The other part goes into receding into the depth "behind" your screen. So a given worldspace distance along the x axis — which points perpendicular to your view — covers more on-...


0

You need to rebake the collider to force the update. wrote this last December but should help you get the position correct. var insertPoint = Input.mousePosition; insertPoint.z = 10.0f; insertPoint = Camera.main.ScreenToWorldPoint(insertPoint); var m = Mathf.Abs((insertPoint - lastPosition).magnitude); if (Input....


1

TL;DR: you are updating the x position value while you want to update the y value. Please have a look at this part of your code: var poss = transform.position; poss.x = Mathf.Clamp(transform.position.x, -8.0f, 8.0f); transform.position = poss; What you're doing here is telling Unity: At every frame, (line 1) I want you to get ...


1

From what I understand the fact to compute your angle on Viewport space messes everything up due to origins. If you do your computation on Screen space everything will work just fine. Update your code with this: var p2 = Input.mousePosition + Vector3.forward * transform.position.z; var p1 = Camera.main.WorldToScreenPoint(transform....


0

From what I see of the values you're using, it appears that New Sprite object is actually BEHIND and not aligned with the camera. So the camera can't see it, and display it. It'd explain why you can see it in the Scene view but not in the Game view.


Top 50 recent answers are included