Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
json
Languages:
English
Size:
10K - 100K
ArXiv:
License:
_id
int64 0
49
| text
stringlengths 71
4.19k
|
---|---|
0 | Character falls through the Platform Effector 2D in Unity. How can I fix it? Character falls through the Platform Effector 2D in Unity. How can I fix it? Here is the demonstration https imgur.com G5YkTxa. I tried changing the Edit Project Settings... Physics 2D Default Contact Offset from the current 0.01 value to the 0.1 value. The result is the same and here is the demonstration of it https imgur.com 3TAOsNY. Here are my settings for the platform Here are my settings for the character's RigidBody 2D Here is what character colliders look like when my character runs https imgur.com CTialU3. I basically run the recorded inside Unity animation of running and move my character with the help of the private void FixedUpdate() ... some code which computes the velocity vector depending on the input (the pressed buttons) characterRigidBody2D.velocity velocityVector I googled for a while now similar issues, but was not able to find a solution. I want to avoid the character falling down randomly during running. |
0 | How to implement the swipe up and down number select Unity3d I want to implement the UI like in the image. I want the users to select the number by swiping up and down. I found the tutorial on the YouTube which is similar to the what i wanted (https www.youtube.com watch?v mL FLsV3WRs) But it shows only the numbers from 0 to 9. I want to show from 1 to N (n can be any number). Any idea to help me to get this would be great. |
0 | Why is there a discrepancy between these two transform.up vectors? I was trying to implement a feature which required transform.up, the result didn't match the green axis gizmo displayed in the editor so I assumed it was being put off by the rotation of the object despite expecting the gizmo to adapt to that. I then modified the prefab such that everything was now child to an empty object and the secondary objects were child to that instead of the rotating model, and wrote a script that simply copies the transform so that it tracks. This still didn't show the values expected from what the gizmo in the editor showed. I then did a Debug.LogError in the track script and this time the result was as expected. Why is transform.up showing the value expected from the local y axis gizmo but when passing a reference to the original script and checking tracked.transform.up gives off results? To reproduce in a simpler environment I set up a simple test scene. Simple default cube with the hierarchy structure shown in the screenshot. The transform values are as follows parent zeroed x 0, y 90, z 0 for cube x 0, y 90, z 90 for TrackPoint Scripts are as follows test.cs attached to trackpoint private void Update() Debug.LogError(transform.up) Track.cs attached to tracker public Transform transformToTrack private void Update() transform.position transformToTrack.position transform.rotation transformToTrack.rotation Debug.LogError(transform.up) byref.cs attached to cube public GameObject refObj private void Update() Debug.LogError(refObj.transform.up) When run, if you clear the console then click pause you'll see that one of them differs from the others. I don't understand why. My project and this sample scene differ in which it is that is giving unexpected results but the results are inconsistent with what I would expect. But wouldn't they all give the same result? |
0 | How to draw an arc between two angles? I'd like to draw an arc between two specific angles. For example, "draw an angle between 0 and 90 degrees" and it will draw only that part of the circle and ignore the rest. |
0 | Achieving 2D Lighting for Terraria Like Game I'm trying to achieve the fog of war lighting style that Terraria and Starbound have. Terraria's lighting system seems to be more blocky tile based, but Starbound's is a lot more smooth. The Desired Effect Starbound is using a shader to render its lighting, but how it's going about that is quite a mystery to me. The idea I had on how to achieve the desired effect is the following Create a texture that is black and somehow calculate the area that is white, storing this in a light map render texture, finally doing an Additive Blend of both the main texture and the light map texture to achieve a similar effect to Starbound's. (However this does not take into account lights in the world, which I also have absolutely no clue how to include in my calculation to the light map render texture) I say somehow in italics because I have no clue as to how I can create this "Mask" effect in the light map render texture. How I can do calculations necessary to create the mask is beyond me I don't even know how I can begin to translate the game world's data, relative to the what the camera sees, and update the texture accordingly. TLDR How can I achieve lighting similar to that of either Terraria or Starbound in Unity 2D? |
0 | Can we merge multiple FBX files, using Maya, and export as a single FBX file? I have a humanoid model which is made up of four FBX files one is for the human, one is for the T shirt, one is for the pants and one is for the hair. I want to merge them into one FBX, because the manner in which I am using it requires using a single FBX file to represent the character. Can we merge four FBX files into one, using Maya, and export as a single FBX file? |
0 | How to avoid game starting before start button is clicked? I've made a game with a Title Screen (Canvas), and a Start Button attached to the Title Screen. Points, GameOver, Restart, and even the Start Button sort of works, but it's possible to play the game before the user presses start. Is there a way to make the GameObjects only appear after the button is clicked? I've tried to move and change the "public void StartGame()", but I can't get it right. This is my first game ever, so hope the code provided is relevant. Enemy.cs void Start() enemyRb GetComponent lt Rigidbody gt () gameManager GameObject.Find("GameManager").GetComponent lt GameManager gt () player GameObject.Find("Player") GameManager.cs public void StartGame() powerup.transform.rotation) score 0 UpdateScore(0) isGameActive true titleScreen.gameObject.SetActive(false) void Update() enemyCount FindObjectsOfType lt Enemy gt ().Length if (enemyCount 0) roundNumber SpawnEnemyIntruders(roundNumber) Instantiate(powerup, GenerateSpawnPosition(), powerup.transform.rotation) void SpawnEnemyIntruders(int enemiesToSpawn) for (int i 0 i lt enemiesToSpawn i ) int enemyIndex Random.Range(0, enemies.Length) Instantiate(enemies enemyIndex , GenerateSpawnPosition(), enemies enemyIndex .gameObject.transform.rotation) public void GameOver() restartButton.gameObject.SetActive(true) gameOverText.gameObject.SetActive(true) isGameActive false PlayerController.cs void Start() playerRb GetComponent lt Rigidbody gt () playerAudio GetComponent lt AudioSource gt () StartButton.cs void Start() button GetComponent lt Button gt () gameManager GameObject.Find("GameManager").GetComponent lt GameManager gt () button.onClick.AddListener(StartThis) |
0 | Counting triangles and vertices in Unity's cube I want to understand logic behind drawing triangles of primitives in Unity. When we spawn simple cube, variable mesh.vertexCount gives us value 24. Also when we list all vertices positions (from mesh.vertices) and triangles numbers (from mesh.triangles), we get 0. (1.0, 1.0, 1.0) 0 1. ( 1.0, 1.0, 1.0) 2 2. (1.0, 1.0, 1.0) 3 3. ( 1.0, 1.0, 1.0) 0 4. (1.0, 1.0, 1.0) 3 5. ( 1.0, 1.0, 1.0) 1 6. (1.0, 1.0, 1.0) 8 7. ( 1.0, 1.0, 1.0) 4 8. (1.0, 1.0, 1.0) 5 9. ( 1.0, 1.0, 1.0) 8 10. (1.0, 1.0, 1.0) 5 11. ( 1.0, 1.0, 1.0) 9 12. (1.0, 1.0, 1.0) 10 13. (1.0, 1.0, 1.0) 6 14. ( 1.0, 1.0, 1.0) 7 15. ( 1.0, 1.0, 1.0) 10 16. ( 1.0, 1.0, 1.0) 7 17. ( 1.0, 1.0, 1.0) 11 18. ( 1.0, 1.0, 1.0) 12 19. ( 1.0, 1.0, 1.0) 13 20. (1.0, 1.0, 1.0) 14 21. (1.0, 1.0, 1.0) 12 22. (1.0, 1.0, 1.0) 14 23. (1.0, 1.0, 1.0) 15 (i th element, vector from mesh.vertices i , number from mesh.triangles i ) Obviously we need only 8 vertices to create cube, but we need 6 2 12 triangles, three vertices every array of 36 vectors. So... what is the logic of Unity primitive? |
0 | Profiling unity games on Android devices I would like to profile our Unity mobile game on Android devices in a way similar to profiling Unity games on iOS with Instruments. I am aware of how to do this using Unity's profiler, I would however like to use a third party profiler for the following reasons to validate Unity's profiling data to have more visibility into how the app is running, including Unity's functions, etc. the largest lag spikes cause unity's profiler to run out of samples. I'm however very interested in precisely these spikes I'd like to have profile data for longer periods than unity records for I'd like to do analysis over time (not just detailed data for each frame, but also aggregated over a time span) Essentially I'd like as much visibility as possible to make Android on device profiling as comprehensive as possible. As close to Instruments on iOS as possible. So far I've tried with DDMS, but could only get visibility into Andoid OS functions and seeminly nothing in the actual apk at least nothing I recognised. I tried with mono2x and il2cpp, with all debug features that I'm aware of in build and player settings enabled. The game is developed with Unity 5,4 with Mono2x. All help is appreciated. I've listed my intents above, so even if profiling on device is not possible in this way on Andoid, alternate solutions to the listed intents are still very appreciated. Thanks! |
0 | Unity3d Get a direction vector parallel to plane I need to send a raycast from my camera which is parallel to the plane (Ground) and in the same direction of its forward vector (Represented by the black color vector) I cant use world space direction because the global forward vector of the camera points at the same direction no matter how much I rotate it (Since its a VR camera) I tried to use Vector3.ProjectOnPlane, but not sure how it works. Can someone help me? |
0 | Top Down 2D Collision C I know this has been asked before, but I don't understand why my code isn't working. I'm doing top down collision with no gravity. Here is my code using System.Collections using System.Collections.Generic using UnityEngine using System public class TankBodyControls MonoBehaviour public KeyCode Foward KeyCode.W public KeyCode Backward KeyCode.S public KeyCode TurnLeft KeyCode.A public KeyCode TurnRight KeyCode.D public const float MaxSpeed 6.0f public const float RotSpeed 4.0f private Rigidbody2D TankBody void Start () TankBody GetComponent lt Rigidbody2D gt () void OnCollisionEnter2D(Collision2D coll) print("called") if(coll.collider.CompareTag("wall")) print("collided!") var P transform.position P.x TankBody.velocity.x P.y TankBody.velocity.y transform.Translate(P) private void MoveTank() var Vel TankBody.velocity if(Input.GetKey(Foward) Input.GetKey(Backward)) float VelMag (Input.GetKey(Foward) ? MaxSpeed 1.0f MaxSpeed 2.0f) float VelAngle transform.eulerAngles.z ((float)Math.PI 180f) Vel new Vector2((float)Math.Cos(VelAngle), (float)Math.Sin(VelAngle)) Vel VelMag var rot TankBody.rotation if (Input.GetKey(TurnRight)) rot RotSpeed if(Input.GetKey(TurnLeft)) rot RotSpeed TankBody.rotation rot else Vel Vector2.zero TankBody.velocity Vel void Update () MoveTank() The idea was if I detect a collision, shift the player out of the wall, the distance (velocity) they intersected it. My problem right now is, the OnCollisionEnter2D function doesn't even get called when they intersect (hence not console prints). Any idea what I'm doing incorrectly? |
0 | How do I include a blend tree in my controller? I want my player to aim up and down with a pistol. I have stored an quot aim up quot pose in one anim file, and I have stored an quot aim down quot pose in another anim file. I want to blend between these 2 poses according to the mouse pointer on the screen If the mouse pointer is at the bottom of the screen, the blend tree should only play the quot aim down quot pose If the mouse pointer is at the top of the screen, the blend tree should only play the quot aim up quot pose If the mouse pointer is at the middle of the screen, the blend tree should play a 50 50 mix of the quot aim down quot and of the quot aim up quot pose To do that, I have added a 1D blend tree to my animator. It looks like this I have tested the blend tree. When I scrub through the quot timeline quot using the red line, it works as expected Now I wanted to test it out in my game, but I don't see how to set the blend weight of this 1D blend tree. The docs say that the blend tree is controlled by the animation parameters. As far as I can see, Unity automatically created one for me when I added the blend tree. The name seems to be quot Blend quot , as can be seen in the screenshot The following however has no visual effect for me animator.SetFloat( quot Blend quot , 1f) To check if this parameter even exists, I have changed its value to 0.3 in the animator. Then in my code, I check the value like this, and it does return 0.3 float fCur animator.GetFloat( quot Blend quot ) So this is proof that the parameter does exist. However, when I set a new value like... animator.SetFloat( quot Blend quot , 0.56f) ... then this value is accepted, but it doesn't have any visual effect, and it doesn't show in the animator's paramters. Can anybody tell me how I could achieve what I want? Edit I have tested it in a new, stripped down project. In this new project, I have the blend tree as the default state in the animator, and everything works. So the fact that my blend tree is NOT the default state in the other project seems to be the problem. This is what it looks like I will first try to investigate more on this. |
0 | How to make the bounced light brighter in unity? I'm using indirect lighting to lit a room. The light is coming through the window, but still the inside is too dark compared to the real light . if i bring up the environment or light intensity, it will look the exterior is burnt out ( too bright)... it's already on the limit. How to just make the bounced light (indirect light) brighter ? |
0 | How to find the minimum number in a float array C Unity i have a for loop that detects the position of every game object in a list and gets the difference between that object and an object anchored in the center and then stores all values in a float array. what should happen next is find the minimum distance in that array and make that object (the object with the smallest distance) move towards the anchored center. the problem is that no matter what i do, it always gets the maximum number (which is the furthest game object). here is what i have so far public RectTransform panal public GameObject characters public RectTransform center private float distance private float minDistance private bool isDragging false private int distanceBetweenCharacters private int minCharNum private void Start() int charLength characters.Length center GameObject.Find("CenterCompare").GetComponent lt RectTransform gt () distanceBetweenCharacters 200 private void Update() for (int i 0 i lt characters.Length i ) distance i Mathf.Abs(characters i .transform.position.y center.transform.position.y) float minDistance Mathf.Min(distance) Debug.Log(minDistance) for (int a 0 a lt characters.Length a ) if (minDistance distance a ) minCharNum a Debug.Log(minCharNum) if (!isDragging) LerpToChar(minCharNum distanceBetweenCharacters) void LerpToChar(int position) float newY Mathf.Lerp(panal.anchoredPosition.y, position, Time.deltaTime 5f) Vector2 newPosition new Vector2( 386, newY) panal.anchoredPosition newPosition public void StartDrag() isDragging true public void EndDrag() isDragging false I assume that the problem is with the array because when i set the minCharNum to a specific integer, it works just fine. What am i doing wrong exactly? Any help is very much appreciated. |
0 | Selected enemy off camera I'm facing a problem with a game I'm making. Currently I can select an enemy and mark it as shown on the image But now I want to show the position of the selected enemy on the screen when it's off camera. So my questions are How do I know when an enemy is off camera. How can I show in GUI an arrow on the edge of the screen that points to the position of that enemy. Perhaps something related to what I did to point towards the crosshair? Vector3 positionOnScreen Camera.main.ScreenToWorldPoint(mousePos Vector3.forward range) Vector3 targetDir positionOnScreen transform.position Thanks! |
0 | How to add isometric (rts alike) perspective and scolling in unity? I want to develop some RTS simulation game. Therefore I need a camera perspective like one knows it from Anno 1602 1404, as well as the camera scrolling. I think this is called isometric perspective (and scrolling). But I honestly have no clue how to manage this. I tried some things I found on google, but they were not satisfying. Can you give me some good tutorials or advice for managing this? Thanks in advance |
0 | Unity Remote 4 on Galaxy S5 won't connect to Unity 5 I'm having some trouble connecting Unity Remote 4 to Unity 5. I'm using a Samsung Galaxy S5. I've searched a bit and the other solutions with other phones aren't working for me. What I've tried so far I installed the Android SDK by using Android Studio. I'm not sure if that's part of the problem but either way. I installed the Google USB Driver, the 5.0 (API 21) and 5.1 (API 22) SDKs. My phone is running on Android 5.0. All the SDK tools (Platform tools and build tools) are installed. I set USB Debugging, Stay Awake and Allow Mock Locations in the Developer Options on my phone. I set the Android SDK path in Unity (Program Files Android android sdk) I set, in the Unity Editor Settings, Device to Any Android Device. I made sure my computer sees my phone, which it does. And I tried to open Unity first then the Unity Remote and Unity Remote first then Unity Engine. And set Android as my Platform in Build Settings. And I've tried plugging my phone in a USB 2.0 and a USB 3.0. All that and each time I press the play button nothing happens in the phone. I have no idea what I'm doing wrong. I tried using Unity 4 and Unity 5. If my OS is a factor, I'm using Windows 7 Ultimate, 64 bit. If the following information is needed Hardware Version G900P.04 Model number SM G900P Android version 5.0 Kernal version 3.4.0 If any other information is needed I will provide it. Anyone have a solution to my problem? Thank you. |
0 | Unity ScrollRect many objects perfomance issue I have scrollrect setup and over 1000 objects to scroll through. Currently i'm Instantiating all the 1000 objects at once and notice fps drop. I'm using 2d mask and disbale pixel perfect. Both gave a perfomance boost, but i still Think the bottleneck is that i have 1000 objects already created on the scene. Instead create what is visible to the eye. What can i do? I've looked into pools. But i dont know how i should use it in my case. Since the inventory is dynamic. public void ShowInventory(PlayerObject player) for (int i 0 i lt inventory.GetContainerSize i ) Item item inventory.GetContainer i Button itemButton Instantiate(buttonPrefab, content) itemButton.GetComponent lt InventorySlot gt ().SetInventorySlot(player, item, item.amount) |
0 | Nestling into contact with a group of physics objects without exerting forces on them I'm making a pool game, and would like the circle (imaginary) to be in contact with the table and balls, and to fit perfectly as a ball would. Now I thought I would use Rigidbody and lerp the position of the circle to the raycast hit, and its collider it would force it into a fitting position. The problem I encountered is that since it has a collider, it also pushes the balls, which I do not want. So my question is, how do I make an object act like it's touching amp blocked by other GameObjects with Colliders and Rigidbodies, without pushing them? |
0 | Get random point on NavMesh async I am trying to spawn some entities on a navmesh at runtime. The entities need to spawn at a random point. Right now i use the following to get a random point public Vector3 GetRandomPointOnMesh() Vector3 randomDirection UnityEngine.Random.insideUnitSphere maxDistance randomDirection transform.position NavMeshHit hit NavMesh.SamplePosition(randomDirection, out hit, maxDistance, 1) if (float.IsInfinity(hit.position.x) float.IsInfinity(hit.position.y) float.IsInfinity(hit.position.z)) return GetRandomPointOnMesh() return hit.position My problem here is, some time that random point inside the sphere is not hitting the navmesh, hence the recursive call until it actually hits the navmesh. How can i make this piece of code run in the background until there is an actual value returned. Cause this holds up the main thread till a value is obtained. |
0 | How to rotate object just like in the scene? Look at this image, I selected an object and pivot is set to local When I rotated selected object in the scene by X axis, it rotates exactly I wanted. But if I rotate axis from inspector or script, it doesn't rotated to desired angle. I'm not sure, but it seems it's related about Quaternion, but everything I tried doesn't worked well. How do I rotate that object just like in rotated from scene? |
0 | How can I disable the red X button in unity? I just want to know how to disable the red X button in the game window using unity, to prevent the player for example from closing the game. So if anyone knows how to do it, any help would be greatly appreciated. |
0 | How to support Surface pens in Unity? Our game works great with touch or mouse, but the Surface pen doesn't seem to register as a pointing device at all. How can we support the pen in Unity in a native build? This question on the Unity Answers site suggests we could build it as a UWP app, but that means restricting ourselves to a very limited subset of the .NET framework (specifically, we lose a lot of the Serialization libraries). |
0 | How to make a delay between animations in mecanim? How to make a delay between animations in mecanim? For example after anim1 ends then there will be a delay then anim2 starts. I tried to increase the exit time but it doesnt work. |
0 | Getting the rightmost point of gameobject How do i determin the point on a gameobject that is most to the right (highest x value). |
0 | After changing the mouse cursor texture how can i resize the texture cursor and how to center it? I want to center it to the middle of screen. And the size i tried to make both width and height 0.02f but it's still too big when running the game. using System.Collections using System.Collections.Generic using UnityEngine using UnityStandardAssets.Characters.FirstPerson public class RotateObject MonoBehaviour public Texture2D cursorTexture public CursorMode cursorMode CursorMode.Auto public bool autoCenterHotSpot false public Vector2 hotSpotCustom Vector2.zero private Vector2 hotSpotAuto void Awake() Cursor.lockState CursorLockMode.Locked Vector2 hotSpot if (autoCenterHotSpot) hotSpotAuto new Vector2(cursorTexture.width 0.02f, cursorTexture.height 0.02f) hotSpot hotSpotAuto else hotSpot hotSpotCustom Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.ForceSoftware) In the screenshot the mouse cursor is the image on the left in the game view and it's not in the center it's a bit on the right bottom(The ball is the mouse cursor). On the right the inspector of the script. The script is attached to the FPSController. |
0 | unity2D swipe control's bool for animator doesn't work i was trying to make a control where the animation plays upon swiping one direction. each time i've make a tap swipe control, it just keeps popping messages like this. the tap animation works fine, but the animation for swipe controls just doesn't work well, the bool for them has assigned but did not make it 'true' when i swipe a direction, but the bool for the tap works, which is weird.(ignore the miss bool in the animator) it says that i need to assign the anim variable of the Swipe script in the inspector. but there is nothing left for me to assign, which doesn't make much sense for me. (refer to Region Animation) i've tried to make some adjustment with the script, but the results is the same, and it has no problems when build. which is why i need help for the animation stuff. using System.Collections using System.Collections.Generic using UnityEngine public class Swipe MonoBehaviour public Animator anim public bool tap, swipeUp, swipeDown, swipeLeft, swipeRight public bool isDragging false public Vector2 startTouch, swipeDelta private void Update() tap swipeUp swipeDown swipeLeft swipeRight false region Standalone Input if (Input.GetMouseButtonDown(0)) tap true isDragging true startTouch Input.mousePosition Debug.Log("Tapped") else if (Input.GetMouseButtonUp(0)) isDragging false Reset() endregion region Mobile Inputs if (Input.touches.Length gt 1) if (Input.touches 0 .phase TouchPhase.Began) tap true isDragging true startTouch Input.touches 0 .position else if (Input.touches 0 .phase TouchPhase.Ended Input.touches 0 .phase TouchPhase.Canceled) isDragging false Reset() endregion region Animation if (Tap) anim.SetBool("Tap", true) if (SwipeDown) anim.SetBool("Down", true) if (SwipeUp) anim.SetBool("Up", true) if (SwipeLeft) anim.SetBool("Left", true) if (SwipeRight) anim.SetBool("Right", true) endregion calculating the distance swipeDelta Vector2.zero if(startTouch ! Vector2.zero) if (isDragging) if (Input.touches.Length gt 0) swipeDelta Input.touches 0 .position startTouch else if (Input.GetMouseButton(0)) swipeDelta (Vector2)Input.mousePosition startTouch did we cross the deadzone? if (swipeDelta.magnitude gt 125) which direction? float x swipeDelta.x float y swipeDelta.y if (Mathf.Abs(x) gt Mathf.Abs(y)) left or right if (x lt 0) swipeLeft true else swipeRight true else Up or down? if (y lt 0) swipeDown true else swipeUp true public void Reset() startTouch swipeDelta Vector2.zero isDragging false anim.SetBool("Tap", false) anim.SetBool("Down", false) anim.SetBool("Up", false) anim.SetBool("Left", false) anim.SetBool("Right", false) public Vector2 SwipeDelta get return swipeDelta public bool Tap get return tap public bool SwipeUp get return swipeUp public bool SwipeDown get return swipeDown public bool SwipeLeft get return swipeLeft public bool SwipeRight get return swipeRight |
0 | Unity3d Transform rotation(angle) help Im trying to rotate an object 90 degrees to the left but instead of rotating straight left it rotates 270 degrees to the right. Here's the part of the code which controls the rotation rotationDestination new Vector3(60, 270, 0) if (Vector3.Distance(transform.eulerAngles, rotationDestination) gt 0.2f) transform.eulerAngles Vector3.Lerp(transform.rotation.eulerAngles, rotationDestination, rotationSpeed Time.deltaTime) If I try to make the Y axis 90 a.k.a (60, 90, 0) then it rotates constantly to the left. How do I make it rotate straight to the left (90 degrees) ? Thank you. |
0 | How do I add a prefab to another prefab? I want to instantiate a prefab, and then instantiate another prefab and then set the second prefab to the first prefab. However, this doesn't work. This is my code instantiate a new weapon prefab Transform nNewInstantiatedPrefab Instantiate(tPrefab, new Vector3(0, 0, 0), Quaternion.identity) if (nNewInstantiatedPrefab null) Debug.Break() instantiate a new amount info canvas GameObject nNewAmount Instantiate(ItemInfoCanvasPrefab, new Vector3(0, 0, 0), Quaternion.identity) if (nNewAmount null) Debug.Break() nNewAmount.transform.SetParent(nNewInstantiatedPrefab) now test if the prefab has been attached to the other prefab Transform nTest Helpers.GoFromName(nNewInstantiatedPrefab, "AmountCanvas") if (nTest null) Debug.Break() this line is called And this is the helper function. I haven't had any problems with it so far public static Transform GoFromName(Transform t, string uName) foreach (Transform g in t) if (g.name uName) return g Debug.Break() return null Am I doing something fundamentally wrong, and perhaps prefabs can't be added to other prefabs? Thank you! |
0 | How can I rotate RigidBody and not violate physics? I'm trying to create a game that we have a falling ball and an spinning object that spin based on user mouse position. user should rotate the object and hit the ball on time to throw the ball into sky. The problem is that if user move his finger too fast. the game object moves too fast and goes past through the ball. This is my code so far void Update () if (Input.GetMouseButtonDown(0)) startPos Input.mousePosition.x startRot obj.transform.localEulerAngles lastDist 0 if (Input.GetMouseButton(0)) float dist Input.mousePosition.x startPos obj.MoveRotation(Quaternion.Euler(startRot new Vector3(0, 0, dist))) for (int i 0 i lt obj.transform.childCount i ) obj.transform.GetChild(i).GetComponent lt Rigidbody gt ().MoveRotation(Quaternion.Euler(startRot new Vector3(0, 0, dist))) How can I achieve this behavior for my game. The user should be able to spin the game object as fast as possible. Thanks in advance. |
0 | What's the difference between UnityEvent and OnTriggerEnter() I'm new into game development and programming and I have a question that might sound silly or stupid, but I'm having issue understanding the difference between UnityEvent and OnTriggerEnter(). I would like to understand what I can do with UnityEvent that isn't possible with OnTriggerEnter(). |
0 | Why transform.find() does not need actual object unity I m new to unity and C . I suspect that transform.find() function below does not need actual object reference like player.transform.find() because it transform find is already applied to the gameObject the script is attached to? Am I right? Why transform.find() does not have any game object in front of it? public class PlayerControl MonoBehaviour private Transform groundCheck void Awake() groundCheck transform.Find("groundCheck") |
0 | How do I create a prefabs when a button is clicked(Unity) So I want to be able to spawn prefabs when a button is pressed Shop script using System.Collections using System.Collections.Generic using UnityEngine public class Shop MonoBehaviour public static string Item01 public static string Item02 public static string Item03 public static string Item04 public static int ShopNum Update is called once per frame void Update() if(ShopNum 1) Item01 quot Cannon quot Item02 quot Tower quot Item03 quot army Camp quot Item04 quot Baracks quot if(ShopNum 2) Item01 quot Archer quot Item02 quot Barbarian quot Item03 quot Goblin quot Item04 quot Wizard quot And then my Shop Access script using System.Collections using System.Collections.Generic using UnityEngine using UnityEngine.UI public class Shop01Access MonoBehaviour public GameObject ShopInventory public GameObject Item01Text public GameObject Item02Text public GameObject Item03Text public GameObject Item04Text public GameObject ItemCompletion public GameObject CompleteText void OnTriggerEnter() ShopInventory.SetActive(true) Screen.lockCursor false Shop.ShopNum 1 Item01Text.GetComponent lt Text gt ().text quot quot Shop.Item01 Item02Text.GetComponent lt Text gt ().text quot quot Shop.Item02 Item03Text.GetComponent lt Text gt ().text quot quot Shop.Item03 Item04Text.GetComponent lt Text gt ().text quot quot Shop.Item04 public void Item01() ItemCompletion.SetActive(true) CompleteText.GetComponent lt Text gt ().text quot Are you sure you want to buy quot Shop.Item01 quot ? quot public void Item02() ItemCompletion.SetActive(true) CompleteText.GetComponent lt Text gt ().text quot Are you sure you want to buy quot Shop.Item02 quot ? quot public void Item03() ItemCompletion.SetActive(true) CompleteText.GetComponent lt Text gt ().text quot Are you sure you want to buy quot Shop.Item03 quot ? quot public void Item04() ItemCompletion.SetActive(true) CompleteText.GetComponent lt Text gt ().text quot Are you sure you want to buy quot Shop.Item04 quot ? quot public void Cancel() ItemCompletion.SetActive(false) How could I spawn a cannon when button item01 is pressed into my 3d scene |
0 | How to calculate a normalized direction of two rotations? In Vector math and translations we can do dir (v1 v2).norm and then v1.translate(dir 50) so v1 moves to the v2's direction. What about rotation and eulerAngles? Here's my attempt, but it doesn't work, probably from some obvious reasons. Vector3 initial ob1.transform.rotation.eulerAngles get it's initial rotation ob1.Rotate(new Vector3(0,0,90)) rotate Vector3 after ob1.transform.rotation.eulerAngles store new rotation ob1.Rotate(new Vector3(0,0, 90)) rotate back to initial here I need to calculate the direction so I can do rotate(dir 50) or something similar I need to get the rotation direction, so I can rotate the object continously with direction, not with a fixed desired angle value. To be super clear, I need to get this blue line direction The object is initially rotated by (0,0,57). I need to rotate it around it's center (green axis). I know I can do logo1.transform.RotateAround(logo1.transform.position, logo1.transform.up, 80) and it works, but I need the direction from this, so I can use it in Tweening. |
0 | Character controller falling with positive speed I'm having very weird problems with my player's vertical movement. I'm using a Character Controller component with a capsule collider and no rigidbody. For testing purposes, I've ended reducing my jump script to just this line owner.CharacterController.Move(new Vector3(0, 0.01f, 0)) When executing this script, the player should just fly upwards at a constant speed, right? Well, what ends up happening is that the player starts jumping in place repeatedly. The jumps are smooth, as if the movement was being affected by gravity. I thought that the standard Character Controller doesn't handle gravity automatically and you have to do it yourself, so I can't understand what's going on here. There is no other code affecting the player, if I comment that line it just rests in place. If I try a different direction (like (0.01f, 0, 0)) the player moves in a straight line in the provided direction as expected. But when moving vertically, weird stuff happens S |
0 | How to know when all 2d rigid bodies have stopped in unity3d? Is there anyway to know if all 2d rigid bodies in untiy 3d phisics world have stopped? |
0 | Shooting the closest enemy that you can see I'm trying to make my main character aim at the closest enemy that he can see. My issue is with the close range criterion taking priority. If the enemy is near the player but the player can't see him, I'd like the player to look for another enemy inside his range. As you can see in the image, There is an enemy behind the wall. The player is not aiming at him because he can't see him. So far this is correct. But the player is also ignoring the enemy in front of him because he's busy rejecting the one behind the wall. What he should do is aim at the one in front of him, because he can see him and he is inside the player's range. using System.Collections using System.Collections.Generic using UnityEngine using UnityEngine.AI using UnityEngine.UI public class clickme MonoBehaviour private NavMeshAgent mAgent public float mark, ToPoint public bool actives, seeEnemy private Transform target public float range, enemyDistance range is player eyes field. public float speed 5.0f public Transform aiming point, playerEye private GameObject targets void Start() targets GameObject.FindGameObjectsWithTag("enemy") target targets 0 .transform seeEnemy false void Update() if (mAgent.remainingDistance lt mAgent.stoppingDistance) actives false if (actives false amp amp playerEye true amp amp target ! null) if (enemyDistance lt range) Vector3 dir target.position transform.position Quaternion lookRotation Quaternion.LookRotation(dir) Vector3 rotation Quaternion.Lerp(transform.rotation, lookRotation, Time.deltaTime speed).eulerAngles transform.rotation Quaternion.Euler(0f, rotation.y, 0.0f) else else actives true updateTarget() end update void updateTarget() GameObject enemies GameObject.FindGameObjectsWithTag("enemy") float shortesDistance Mathf.Infinity GameObject nearestEnemy null foreach (GameObject enemy in enemies) float distanceToEnemy Vector3.Distance(transform.position, enemy.transform.position) if (distanceToEnemy lt shortesDistance) shortesDistance distanceToEnemy nearestEnemy enemy RaycastHit hit can I see my closent enemy or not ? if (Physics.Linecast(playerEye.position, nearestEnemy.transform.position, out hit)) Debug.DrawLine(playerEye.position, nearestEnemy.transform.position, Color.blue, range) if (hit.collider.tag "enemy") seeEnemy true print(" I can see enemy !") else seeEnemy false print("No enemy here!") end foreach if (nearestEnemy ! null amp amp shortesDistance lt range amp amp seeEnemy true) target nearestEnemy.transform aiming point target.transform.Find("aim") enemyDistance Vector3.Distance(transform.position, target.transform.position) else target null aiming point null seeEnemy false enemyDistance 0 end target |
0 | How to select multiple frames from a sprite sheet in unity I have a sprite sheet and cannot figure out how to select multiple frames in unity 5.5 I am watching a tutorial and it doesn't say how to do it. Is there a button I have to press while clicking or is it having to change some settings? |
0 | Get the scene that MonoBehaviour belongs to (multi scene setup) Is there a way to get the scene that a MonoBehaviour component belongs to? The MonoBehaviour is part of a setup with several additivly loaded scenes. What I'm looking for is not the currently active scene but an additionally loaded one. |
0 | Unity Editor stops updating ScriptableObjects if I click away from them in editor I'm trying to be better about structuring my code, and I think I'm doing it right. The issue I've got right now is I need to get joystick inputs, scale those values appropriately, and then use that scaled data on any number of MonoBehaviour scripts. I'm trying to split the input conditioning from the end user, and I'd like to do that by using a ScriptableObject to hold the conditioned data. I was thinking that a MonoBehaviour script would run, get the joystick data, scale it, and then push that data to variables in the ScaledJoystickData ScriptableObject. Later, a second MonoBehaviour script would access the variables in the ScaledJoystickData and use those to move the things in the game. I'm understanding the benefits of structuring the code this way, especially in that I can access the ScriptableObject from the editor and manipulate those values I don't actually need to have a joystick connected, and I'm free to test either end of the input handling independently. The problem is that, if I am looking at the ScriptableObject instance in the editor, it stops updating as soon as I click away from it (to the consuming GameObject). If I click back to the ScriptableObejct instance, none of the values update. Nothing on the GameObject's script updates unless I start the game with that GO selected in editor, and again THAT fails to update if I click off and click back. The GameObject script is currently using the values from the ScriptableObject instance and piping them to public variables, and the public variables aren't updating. Is there some bug with ScriptableObjects, or am I doing this wrong? EDIT Here's an example. Make a script called "ExampleSO" and replace the contents with using System.Collections using System.Collections.Generic using UnityEngine CreateAssetMenu public class ExampleSO ScriptableObject public float stashedVar 0f Make a script called "ExampleWriter" and replace the contents with using System.Collections using System.Collections.Generic using UnityEngine public class ExampleWriter MonoBehaviour public float scaling 2f public float scaledInput 0f public ExampleSO exampleSO null Update is called once per frame void Update() if(exampleSO! null) scaledInput scaling (Input.GetKey(KeyCode.LeftArrow) ? 1f 0f) exampleSO.stashedVar scaledInput Make a script called "ExampleReader" and replace the contents with using System.Collections using System.Collections.Generic using UnityEngine public class ExampleReader MonoBehaviour public float display 0f public ExampleSO exampleSO null void Update() if(exampleSO! null) display exampleSO.stashedVar Create an instance of the ExampleSO, add the ExampleWriter to a game object, and put the ExampleSO instance into the ExampleWriter slot. Highlight the game object holding ExampleWriter and run it. Push the left arrow key and see the value toggle 0 2. Click the ExampleSO instance. Nothing is happening there now. Click back on the game object, and now it doesn't update either. If you have the ExampleReader on the same game object then it won't work at all. ExampleReader will read fine, if you have it on a separate GameObject, but again if you click off and click back then it stops responding. |
0 | Ball passing through box collider My ball which has a circle collider 2D component occasionally passes through my box collider2D object. Both objects have rigidbodies attached. I have set a high mass for my box collider and a small mass for my ball. Strangely enough, it doesnt pass through every time (maybe due to varying velocity). Basically i am making pong. |
0 | Custom node editor in Unity Im currently making a game on unity, and in the game i want to make quest system to be flexible, as the game world is generated randomly. I also want to make it easy to create quests for myself and possibly modders. So i want to make a menu for creating quests, however i couldnt find any info on how to make node editor window in unity(like shader graph, vfx graph, etc.). How do I do this? |
0 | Changing the RotateAround center point dynamically Black circles are static Red player Blue line path I'm trying to achieve a constant movement of the red dot like on the image below. For now, I have something like void Update() target firstCircle here I need to perform some calculations this.transform.RotateAround(target.transform.position, Vector3.forward, speed Time.deltaTime) As you can see in the code, it rotates around the upper circle now. I need to switch the target variable to the secondCircle when the player comes back to it's initial position (or is near it). I came up with something like if(Mathf.Abs(Mathf.DeltaAngle(360f,this.transform.rotation.eulerAngles.z)) lt 5f) change target and it works but has two issues. First the epsilon value. If I set it to 5f the above if is true like 7 times (depending on the player's speed). Of course I could make a lock to run it only once per cycle, but there's a second problem. If the object is moving too fast, the if will be false each time, cause the speed step is always higher than the epsilon. How is this done in 'gravity' games like AngryBirds when the bullet changes it's attraction point? |
0 | Rewriting a text object I'm trying to set up a UI system. Say I have a text object 'text' which is visible onscreen. I want to change it with a button press using a script such that the text box's previous string is replaced with a new string held in a string variable 'chat'. using System.Collections using System.Collections.Generic using UnityEngine using UnityEngine.UI public class textchange MonoBehaviour public Text text the text box gameobject is dragged into this public string chat the chat string is filled elsewhere void Awake() void Update() (if button press logic here) text.text chat What I expect is for the text to dynamically change, but what happens is absolutely nothing, the gameobject does not have its text component rewritten. What gives? |
0 | Animator consecutive set parameter problem I'm having a little problem with my animations transitions. I have this diagram http imgur.com Se8Ix1L My transitions is made by updating the parameter "stateparam". My code, changing the parameter http imgur.com HlypG2L I change stateparam to 2 and right after to 0, then my animation don't restart every frame. But when I play, the my parameter doesn't change the animation and only change the stateparam to 0. I already debugged and it's passing in the line that change to valid transition value. But i don't know why my animation doesn't changes. If I play and change stateparam manually, it works. If I take off the SetInteger "0", let only the valid value, the code works, but my animation keep restarting before it can finish itself. I don't know if the parameter change it's too fast to do the transition or it's any buggy. Any help ? |
0 | Voice Recorder in Unity I am using Unity for a user study and I am trying to integrate audio interview questions in the game itself. I need to record the user's input to an audio file. The closest thing I found was in this thread. https forum.unity.com threads save microphone recording to disk.378038 It works but it tries to save a 5 minutes clip at once. So, it takes a few seconds and the whole game is stuck for a few seconds. I want to create a thread that will continuously write the shorter clips to the file. I tried using a coroutine but I am having a hard time managing the header as it is dependent on the whole clip. Any suggestions or links to any threads I might have missed will be appreciated. Thanks! |
0 | Function Not Storing New Value of Variables? I'm currently building a small scope RPG and running into an issue with modifying variables. My goal is to alter my character's stats when I run a procedure to change their equipment. My code is as follows public class Player MonoBehaviour Base stat variables public static int PAtk 12 public static int PDef 6 Battle exclusive stats. Will have equipment added onto them. public static int Attack PAtk public static int Defense PDef Equipment variables. public string weapon public string armor private void Awake() Get equipment EquipWeapon( quot Bronze Sword quot ) EquipArmor( quot Bronze Armor quot ) void EquipWeapon(string WeaponName) weapon WeaponName EquipmentManager.GetComponent lt Equipment gt ().EquipStatIncrease(PAtk, Attack, PDef, Defense, WeaponName) void EquipArmor(string ArmorName) armor ArmorName EquipmentManager.GetComponent lt Equipment gt ().EquipStatIncrease(PAtk, Attack, PDef, Defense, ArmorName) public class Equipment MonoBehaviour Create dictionary to give each weapon a key ID. This will be used for calling items in another array. Dictionary lt string, int gt WeaponDictionary new Dictionary lt string, int gt () Create weapon array for stats. public int , WeaponStats Start is called before the first frame update void Awake() Declare weapon IDs WeaponDictionary.Add( quot Bronze Sword quot , 0) WeaponDictionary.Add( quot Bronze Armor quot , 1) Declare stat array Table ID, Atk, Def WeaponStats new int , 0,4,0 , 1,0,4 public void EquipStatIncrease(int BaseAtk, int BattleAtk, int BaseDef, int BattleDef, string Equipment) BattleAtk BaseAtk WeaponStats WeaponDictionary Equipment , 1 Debug.Log(BattleAtk quot Battle Power quot ) BattleDef BaseDef WeaponStats WeaponDictionary Equipment , 2 Debug.Log(BattleDef quot Battle Defense quot ) The general gist of it is once EquipWeapon or EquipArmor is ran, the equipment variables in the Player class will be updated. Afterwards, another function in the Equipment class will be ran with variables from the Player class passed over, in order to be modified by the WeaponStats array. The Debug logs in EquipStatIncrease show me that I am getting the desired results. However, the Attack parameter that is being placed into the function is not being permanently modified. During the first execution of the EquipStatIncrease method, I will get a result of 16 BattleAtk and 6 BattleDef, due to the weapon being equipped. However, once it's run a second time to equip the armor, I'm shown a result of 12 BattleAtk and 10 BattleDef, even though BattleAtk should have stayed at 16. This leads me to believe that the variables I'm trying to transform are not being modified, and I'm not sure what to do about this. In the EquipStatIncrease parameters, BattleAtk gives the message Parameter 'BattleAtk' can be removed if it is not part of a shipped public API its initial value is never used However, I don't know what action to take to resolve this. I'm aware of being able to use an int function instead of void, but unless I'm missing something, that only works if I'm trying to change one variable. If I want to have an equipment object that affects 2 different stats at once(ex. a weapon that increases BattleAtk and BattleDef), then I don't see how an int function would work. |
0 | How to detect if I click on an object (2D) using Raycast? I need to know this for a little popup I made in my game, I want to avoid using OnMouseDown because I have multiple cameras so I was wondering how I'd be able to detect a mouse click event on an object using Raycasting, as I can't figure it out Thank you! |
0 | Drawing an arrow using the LineRenderer in unity I'm trying to draw an arrow using a LineRenderer in Unity, using the code suggested here. Based on the UI it all seems good, yet it draws a pin needle, rather than the arrow I would expect from the UI. If I understand the UI right, it should thicken 60 into the line and then become thinner again towards the end. Any idea what might be going wrong? |
0 | Crate destroy when in trigger and button E pressed There are no errors in the console but I feel like im doing something wrong. The crate is not destroying when I click E. public class CrateDestroy MonoBehaviour public GameObject crate void OnTriggerStay2D(Collider2D other) if (other.CompareTag( quot Player quot )) if (Input.GetKeyDown(KeyCode.E)) Destroy(crate) |
0 | Selecting Dictionary item based on custom classes instead of keys I am attempting to write my own path finding code for a game I'm working on that will implement a form of the A algorithm. I store my nodes of the path finding system as a class called nodes and add these to a dictionary with their position in world space as the key for the dictionary. Here's the problem. At one point I need to test the dictionary and return from it the node with the lowest "f" value. I came across the morelinq MinBy function with seemed promising, but so far have not had any luck getting it to work. Here is a stripped down version of the code using UnityEngine using System.Collections using System.Collections.Generic using System.Linq using MoreLinq public class GMove MonoBehaviour public Dictionary lt Vector3, Node gt vectorNodesOpen new Dictionary lt Vector3,Node gt () public Dictionary lt Vector3, Node gt vectorNodesClosed new Dictionary lt Vector3,Node gt () private KeyValuePair lt Vector3, Node gt currentNode new KeyValuePair lt Vector3,Node gt () private bool goal private bool findingPath void Start() goal false findingPath false public void addNodes() several nodes get added to the dictionary based on the A algorithm ending way point and beginning waypoint are stored as Vector3 public class Node public int h get set public int g get set public int f get set public Vector3 pos get set public Vector3 parentNodeVector get set void Update() if(findingPath) while (!goal) currentNode new KeyValuePair lt Vector3, Node gt (vectorNodesOpen.MinBy(x gt x.Value.f).Key, vectorNodesOpen vectorNodesOpen.MinBy(x gt x.Value.f).Key ) This is the line in which I'm attempting to get the node in the open list with the smallest f value. vectorNodesClosed.Add(vectorNodesOpen.MinBy(x gt x.Value.f).Key, vectorNodesOpen vectorNodesOpen.MinBy(x gt x.Value.f).Key ) vectorNodesOpen.Remove(vectorNodesOpen.MinBy(x gt x.Value.f).Key) remove current from open. if (currentNode.Value.pos waypointEnd) if current node end position we are done. goal true addNodes(currentNode.Value.pos, waypointEnd) Add and update nodes The line that is giving me trouble is the first line inside the while loop. I need a way to return the Dictionary item with the smallest "F" value, this would be pretty easy if it were an integer but the F value resides in the Node class. I don't have to use MoreLinq, I would be happy to do it any other way that someone can come up with. Cheers! One more note the code above is incomplete in an effort to minimize it down to only what is necessary to understand the problem more complete code can be provided if necessary. |
0 | unity2D Top Dow Mobile rigibody2D im using this code for my 2D TopDown mobile player movement.but when i move player With UI Image buttons player keep moving.it didnt stop.and also player starting of move he is very slow. the he accelerate his speed.how can i fix this. i add BoxCollider 2D and Rigibody2D my sprite.the set Gravity to 0. this is my code. public class PlayerScript MonoBehaviour public float speed 150f float hInput void FixedUpdate() Move (hInput) public void Move(float horizontalInput) if (horizontalInput.Equals(1)) rigidbody2D.AddForce (Vector2.right) if (horizontalInput.Equals(2)) rigidbody2D.AddForce ( Vector2.right) if(horizontalInput.Equals(3)) rigidbody2D.AddForce (Vector2.up) if(horizontalInput.Equals(4)) rigidbody2D.AddForce ( Vector2.up) public void StartMoving(float horizontalInput) hInput horizontalInput |
0 | How to make objects collisions act differently I am making an arkanoid type game and have it mostly working. I can destroy the bricks when hit by the ball, but I am adding a twist. I want to have a object on top of the bricks that will interact with the bricks but not destroy them. It needs to still be affected by gravity and collisions because when you collect them all you win the game(you collect them by getting rid of the bricks below them. Everything is pretty much working except for when this object collides with the bricks it triggers the destroy function within the brick script. I am using C and unity 4.6.9. Thanks in advance! I can give pictures and scripts if people want, IDK what would be exactly relevant here though because I'm not sure if this is something done in unity, in the brick script, or in the falling object script. |
0 | Why would Rigidbody.AddForce not resulting in movement of my objects? I'm trying to get my card objects to spread out randomly but nothing happens. I know the method is called cause I get the prints in the console for each card. But they don't move. No errors reported. The cards have a RigidBody. public static void CardCascade () print ("CARD CASCADE!") foreach (var card in Card.Cards) float range 500F var x Random.Range ( range, range) var y Random.Range ( range, range) card.rigidbody.AddForce (x, y, 0) print ("I just added force to card X Y " x y) |
0 | how to reset etsa function GetJoystickNames in unity? the problem is that if I connect a command the array GetJoystickNames increases an index but if you disconnect it does not reduce the index and continues counting as if it were connected |
0 | How can I exclude an object from receiving shadows? I would like to make it so that a certain object is being excluded from receiving shadows. While it itself should cast shadows onto other objects, it should not receive shadows from other objects. How can I achieve this? I'm using HDRP. Seemingly, the option not to receive shadows is not present when using HDRP. The MeshRenderer looks like this |
0 | How to give a Jerk Effect when the player is moving left of right float amttomove Input.GetAxis("Horizontal") playerspeed Time.deltaTime transform.Translate (Vector3.right amttomove) Currently, I have above script in Update function to move the object to left or right.But this movement is way smoother.To give it more realistic feel, I want it to have a slight jerk when it stops moving to left or right and not just stop right there and then. What exactly needs to be done to have that effect? |
0 | Google Play exclude devices I have a game that I'm developing in Unity. The game will be released for Android, so I'm working with the Google Play Console. The thing here is that I don't know how to block (Made not available) some devices with certain properties. For example, I need to made my game NOT available for tablets and for devices that don't have at least 1 GB of RAM. Does anyone know how can I do this? |
0 | Complex layout in Unity I need ScrollRect, but at startup I don't know how many elements it should keep. Moreover this elements should be kept in categories that can fold unfold. The problem is that height of content doesn't updates after folding unfolding. This worked in Unity 5 with ContentSizeFitter in content and each category, but this doesn't work with Unity 2017. Items are added at runtime with instantiating from prefab in a certain category. Is there any solutions without additional scripting? EDIT Additional screenshots When unfolded can't scroll anything because content size is too small This is script part for instantiating items inside categories. |
0 | Determine if AI can traverse a given spline I have some AI Agents that I want to navigate along a spline. The agents have a speed and a maximum turning radius. For some splines the curvature is too tight for the AI agents to navigate around and they end up shooting of the spline and then turning, which looks weird. How can I take a given spline and find the segments that are too tightly curved for a given agent to traverse without shooting off? I thought about just taking the angle between control points, but that alone won't account for the speed limitations that I want to impose as well. Can someone point me in the right direction? I am using Curvy for my spline implementation but using my own agent movement system to walk along the splines. http www.fluffyunderware.com pages unity plugins curvy.php |
0 | NullReferenceException until tile is spawned I have a tile and tile has enemies spawn positions, and spawner script in it. Everything works fine when tile is spawned, my ray hits the collider in tile and enemies get spawned, but my spawn script is in tile my ray script is in my player so im reaching from my PlayerMove script to spawner script, but until my tile is spawned i get this error NullReferenceException Object reference not set to an instance of an object because tile is not spawned yet after its spawned error stops, but after tile is deleted it starts again how can i get rid of this error. PlayerScript private Spawner spawner private RaycastHit hit private void Update() spawner GameObject.FindGameObjectWithTag("Spawner").GetComponent lt Spawner gt () DrawRay() private void DrawRay() Ray ray Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)) if(Physics.Raycast(ray,out hit)) if(hit.collider.tag "SpawnerCollider") if(hit.distance lt 5) Destroy(hit.collider) spawner.Spawn() SpawnerScript public Transform spawnPos public GameObject fireBall public void Spawn() for (int i 0 i lt spawnPos.Length i ) Instantiate(fireBall, spawnPos i .position, Quaternion.identity) |
0 | How to connect a skeleton to an animator at the parent I have two different meshes with similar armatures. And the parent contains the Animator Component with a universal avatar and animation controller. The animations doesn't apply when the bones are not the imminent child of the Animator. Is there a way to get this working? |
0 | How to dynamically construct a reference to a game object by name I have game objects tagged MenuOption0, MenuOption1, MenuOption2, etc. I want to keep a currentIndex var, which gets incremented each time the user swipes on the controller. That swipe should increment the currentIndex var, and switch the reference to a new game object, whose text color will be changed. This is what I'm trying as a test GameObject testText GameObject.Find("MenuOption" 4) TextMeshProUGUI thisTextMesh testText.GetComponent lt TextMeshProUGUI gt () thisTextMesh.color colorWhite How do I dynamically construct a reference to MenuOption1,2,3,4,etc? Or is there a better way to handle this without writing a big long conditional? |
0 | What does the number in TextMesh.lineSpacing refer to? I have a TextMesh with some text, and mutliple lines. The 4 examples have these settings lineSpacing 220, characterSize 10 lineSpacing 220, characterSize 25 lineSpacing 220, characterSize 30 lineSpacing 110, characterSize 25 I don't understand what the lineSpacing number signifies. It's not pixels. As the relative spacing between lines stays the same with different character sizes, it doesn't seem to be proportional to characterSize either. |
0 | Part of model in Unity is inside out but not in Blender? I've downloaded this asset and it looks perfectly fine in preview, and even in blender. But when I import it in Unity, one of its shoulder is inside out, even after making all faces double sided. I also tried switching the normal mode in the import settings to Calculate. What causes this issue and how could I fix this? |
0 | Increase animation speed according to the swipe speed in unity for Android I have the animation done through Maya and brought the FBX file to unity. Here is my code to calculate the speed of the swipe Vector2 speedMeasuredInScreenWidthsPerSecond (Input.touches 0 .deltaPosition Screen.width) Input.touches 0 .deltaTime Now I wanted to take speedMeasuredInScreenWidthsPerSecond and use it to increase the animation speed accordingly like this animation "gmeChaAnimMiddle" .speed Mathf.Round(speedMeasuredInScreenWidthsPerSecond) However, this results in an error that I need to convert Vector2 to float. So how do I overcome it? |
0 | Creating placement grid in Unity I'm fairly new to C and Unity, so I don't really know much about it. I want to create an RTS like game where you have a huge grid that the whole world is placed on. Then you can place houses, walls etc on the tiles just like a lot other RTS games (i.e. Age of Empires, Stronghold Series etc). How would I go about this in Unity? I could imagine having some Terrain World manager that handles all the models and objects that you can interact with etc. And probably a lot of prefabs too with the different items, soldiers and so. So if anyone have any smart way of doing this or maybe a link to a tutorial explaining, then the help would be greatly appreciated. |
0 | Prevent Unity optimizing local variables out Is there a way to instruct Unity compiler not optimize (best only for builds run from Unity editor)? More precisely, I would like it to stop removing local variables, because it complicates debugging. For example, inspecting node void Generate() var node new Node() node node breakpoint here, node cannot be inspected var x nearest Nearest(new node) Debug.Log(new node) new node still cannot be inspected, but x nearest can Node Nearest(Node node) node is an argument here and can be inspected in Visual Studio produces error rather than displaying its value. The identifier node is not in the scope A solution would be make every local variable a private member instead private Node node void Generate() node new Node() node node breakpoint here, node can be inspected this would, however require frequent back and forth refactoring. I am using Unity 5.6.0f3 with C 6.0 support and Visual Studio 2017. note provided code is for illustration only and the question is not about debugging said code because reproducing specific compiler behavior is not trivial |
0 | Mathf.Clamp not Working Properly I want to clamp the vertical rotation of the first person controller I was making. I want to restrict the vertical rotation of the main camera between 90 and 90 degrees. The code is as follows using System.Collections using System.Collections.Generic using UnityEngine public class MouseY MonoBehaviour SerializeField private float sensitivity 5.0f private float verticalInput Update is called once per frame void Update() verticalInput Input.GetAxis( quot Mouse Y quot ) sensitivity Vector3 lookDirectionY transform.localEulerAngles lookDirectionY.x verticalInput lookDirectionY.x Mathf.Clamp(lookDirectionY.x, 90f, 90f) transform.localEulerAngles lookDirectionY In the above code, Mathf.Clamp does not work for 90. On reaching 0 degrees, it reels back to the 90 degrees. What could be the reason for this and how to resolve it? |
0 | How can I change a sprite used for a Unity Tilemap tile at runtime? I want to change Tile's sprite during runtime, but it doesn't render. class SwitchableTile Tile usable sprites public Sprite sprites index to the sprite private int spriteIndex 0 I don't know when it's called but set sprite to current spriteIndex public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) .. if (sprites ! null amp amp sprites.Length gt 0) tileData.sprite sprites spriteIndex called per Tilemap.RefreshTile public override void RefreshTile(Vector3Int position, ITilemap tilemap) tilemap.RefreshTile(position) Also tried to refresh the tile according to the position in MonoBehaviour BoundsInt bounds tilemap.cellBounds bool updated false foreach (Vector3Int pos in bounds.allPositionsWithin) TileBase tile tilemap.GetTile(pos) if (tile amp amp tile is SwitchableTile) if (!updated) just loop index Sprite sprite ((SwitchableTile)tile).GetNextSprite() set sprite ((SwitchableTile)tile).sprite sprite updated true refresh tilemap.RefreshTile(pos) Since Tilemap.RefreshTile calls TileBase.RefreshTile per refresh, the problem's solved after I implemented TileBase.RefreshTile. I'm not using 2d extra's animation tile because I want to change sprites only under certain condition. Also not using Tilemap.SwapTile because in this case I'm solving it using customized Tile, instead of creating a new Tile. Update Well...It proves that I need to implement RefreshTile for a Tile. Now the sprite refreshes. But I'm still not sure about GetTileData, do I need to implement it? When it is called? |
0 | What should I set my managed stripping level to? I know the higher the Managed Stripping Level the smaller binary size but I also know the higher the level more issues you can run into so I have some questions about all this. If I set my managed stripping level to high will I see the effect of that and be able to properly test it when running my game in the editor or would I have to compile to make sure everything runs alright? Can issues with a high managed stripping level be platform specific (Meaning a high level is good on one platform but causes issues on another)? Does managed stripping level only effect binary size or can it also effect performance? If it can effect performance would a binary with a high managed stripping level run faster than a binary with a low managed stripping level or would it be the other way around? |
0 | how to implement ARVR controller in unity vuforia hello i've been strugling figuring out this thing. i'm trying to make ar controller for my vr cardboard game, so the idea is using AR and VR simultaniously. you will completely in vr game but your phone camera wil be turned on and set to AR mode. while you're in vr mode and your AR camera will detect your marker and repositioned it based on your view and the distance between camera and object. that marker will appear in your vr game and you'll make it as a controller. then maybe you want to make that marker appear as a gun, a sword, a shield or whatever it is that can be work with this concept or maybe you just can watch it to get the idea if my explanation is not clear enough https www.youtube.com watch?v a v a23u6n0 so i'm trying to implement it with vuforia as it's augmented reality API and of course Unity. now i'm on the stage where i already now how to use AR amp VR simultaniously and how to transtition between AR to VR or otherwise. i'm still strugling on how to re potitioning my marker to correct position in my VR world. i already tried asking this in vuforia forum but there's still no answer until now. if you guys can help me with this it would be a big help !! thx before |
0 | Unity Android Immersive mode leaving a black bar in the soft key area? The black bar is not hiding anything. Everything is drawn above it. But the black bar is there in place of the soft keys even when they are hidden. I don't know how to hide it and render using whole screen. The bar is only visible with device having soft keys not for device with physical keys. I have set the Screen.fullScreen true. Unity 2018.3.4f1 |
0 | Game build crashes on scene load I built out my project to Android to do some testing and stuff, but I can't get any further than the main menu scene. I built it out previously and it was running fine. Now as I try loading level0 it crashes with no error messages from adb logcat. Just exits the game and that's it. It works fine in the editor. I tried several things. I changed the color space back and forth, I built my addressables, tried development built and non development one, and the Split application binary checkbox is false as well... Unity 2019.2 My adb catlog output |
0 | Importing .anim files created using the Unity Animation controls Our artist created some .anim files using the built in Unity Mecanim system (where you use keyframes and drag various body parts to construct the animation). However, now we're trying to export them from her Unity program into mine so that I can incorporate them into the scene. The problem is that they're simply appearing as blank files. Here, the files are importing and everything looks fine aside from the controller However, once it's imported, it just shows up as a blank unrecognized file She's exporting everything as a .unitypackage and I'm importing the .unitypackage, but it doesn't work for some reason. In addition, she was able to create a new project on her computer and import the package fine. Any ideas why mine is funking up? |
0 | Constructing a building in the "Past" scene, and finding a different version of it in the "Future" scene I am trying to create a game where one scene would be the quot Past quot and one scene would be the quot Future quot . The player can travel through a portal to move between the past and future scenes. In the past scene, the player makes a wooden house and in the future scene it will be turned into something else. There can be multiple instances of these buildings in different places in the scene. So far, I've tried... Using DontDestroyOnLoad to carry the object through from the past to future when loading between scenes. Using singletons to avoid duplicating the object multiple times when loading back and forth. But that has a problem using singletons causes restricts me to just one instance of the building per scene, and I want to have several. The reason why I wouldn't want to unload the old object when the scene unloads is because I wanted the player to be able to build in any area available within the scene. Something like the Fallout 4 building mechanics, where you can build in certain areas and keep those buildings, but I want it to become a different prefab in the future scene. How can I implement a feature like this? |
0 | Unity, shader, vertexID I'm writing a shader and I just wanna ask if it's possible to get the ID of the vertex that is currently being manipulated. I read something about gl vertexID, but I couldn't find out if that is something I can use. |
0 | Third Person Flying Camera I am having issues creating a third person camera for my Rogue Squadron (N64) like game. First I have posted my issue on the official Unity Answers site here. So far my ship is behaving as I want and the camera follows position correctly (XYZ), however, it doesn't rotate how I would like. My first attempt was to set the rotation of the camera to the rotation of the ship and realized that is not what I am looking for either. I have found some information on rotating around a (pivot) point but I am having trouble understanding them. For example, I have found this and this but Im not sure how they work. The end result would be something like the camera found here. Thank you for any help, I would greatly appreciate a description of what you are doing how it works. Lastly this is done in C in Unity. I can provide my code if needed. |
0 | Unity 2D Graphics Optimization For Mobile Devices I want some advices on how to create graphical assets for mobile devices so that the game will have a good performance and not lag on mobile devices. I had 3 issues with my games and that is they all lag after playing a little while, some lag more some less but they all lag, I think the problem is in the graphical assets. Some of the games were simple as flappy bird with a couple of images in the project but the game was lagging after playing it for a minute or two. Now my question is, how to create graphical assets, do I need to export them on 16bit or 32bit and what is the difference, which options should I set in unity, compressed, true color, 16 bit? And are there some other options that I can check or uncheck in unity so that the graphics will perform better on my game? When I pack my assets in a sprite sheet, should I put them on larger sprite sheets for example 2048x2048(which is one of the options for max size in unity) or should I pack them on smaller sprite sheets? Does a sprite sheet have to be to the power of two e.g 1024x1024 or 512x512 or I can pack my assets until they fit and the size does not matter for example the sprite sheet can be 640x410 or something like that, not on the power of two? Does it make a difference when there is free space in a sprite sheet does that affect graphic performance or do I need to squeeze the sprites closer to each other so that there will be no empty space in the sprite sheet? Please answer the question that I'm asking, last time I posted the same question people started asking me about the game, did I do this or that and my question then went off topic and got closed, the game is not the question, the question is everything that I mentioned above or if you have something to add that will help me. If you can help me about this then please answer, and again please don't ask about the game and did I do this or that in the game. I hope that my question is clear, and that it is not off topic. |
0 | How do you unzip a Texture2D from image or string from txt from a zip file using SharpZipLib How do you unzip a Texture2D from image or string from a txt file contained in a zip file using SharpZipLib or System.IO.Compression? |
0 | Particle system appear inside UI? How to make the particle system appear inside the Canvas ? No need for unity store assets. I'm using Unity 5.5.0 |
0 | How can I make Maya or Blender model work with mecanim? I'm working on a simple game project, where I need a stick figure. Due to being stubborn and the desire to learn a new skill, I want to make the stick figure myself! I have followed several tutorials in both Maya and blender. For Maya, I'm using the student version. I have my stick figure rigged within Maya and blender, both utilizing their respective bone tools. I can manipulate their limbs well, enough. However, I can't seem to get the models to work with Mecanim. I have the Kinect adapter for the PC and would like to be able to use it to create the animations utilizing a tool such as the Kinect v2 mocap animator. How I can get my model to work with Kinect based mocap? |
0 | Can you use a standard multi thread if only reading unity objects? First of all I know about coroutines and how to use them (they're awesome). A friend of mine was telling me about the way the he implemented his saving system in a game he was working on, after asking him what he was using I found out that he is using system.threading and not coroutines to save data. I know that Unity isn't thread safe but apparently he has had no issues with saving which leads me to wonder if it is ok to use normal threads as long as you're only reading data and no pre existing data is modified in the gameworld? would this affect the game at all (other than some moving objects being slightly ahead of where they should be because of the time it took to get to that object and save it)? |
0 | How to align 2 IMUs' quaternions? Suppose I have 2 IMUs that output 2 quaternions. I place one IMU on my left hand and another one on my right hand. I put both my hands flat on the table and point it forward to the same direction. What I expect is that they should give very similar quaternion. But it turns out that the IMUs reading differs about 10 20 degrees around the Y axis when plotted in Unity3D. This means I cannot just apply the quaternion to the hand model inside Unity directly. I need to know the exact offset of this 10 20 degrees error in order to make the hand model point in the same direction. How do I figure out this offset automatically? Or is there another way that I can align both IMUs? How do people deal with this IMU problem? PS. Putting the IMU on the hand is just an example. I can put them both directly on the table near each other and they still give slightly different quaternions. |
0 | Mouse input position is being printed as Unity coordinates, but the actual coordinates used seem incorrect This will be hard to explain, but I'll try to keep it short and simple I'm trying to set the position of a UI rectangle to the position of the mouse when clicked. When initialized, the position of the rectangle works fine (if, during Awake(), I initially set it so that x 100 and y 100 and then check the Rect Transform component during run time, Pos X and Pos Y are both set to 100 as intended). However, if I use the X and Y coordinates of Input.mousePosition, Pos X and Pos Y are given strange numbers that I have no clue where they're coming from. I don't think they're pixel coordinates because the value for Pos X of the rectangle when my mouse clicks at the farthest left possible during run time is a value over 300 when it should be 0, and that value goes up as I progressively click rightwards. Now here's the strange bit. When I try to use print() to print the mouse position x and y values that I use to set the rectangle's position, they're printed as intended (clicking the bottom left of the game area yields x 0 and y 0) yet the rectangle's position is far from close the values printed (rectangle's position is x 337.5 and y 192.5). Can someone please explain why this happens, and how I can fix it? I suppose I can manually fix it by subtracting the new position values by 337.5 for x and 162.5, but it feels too brute force ish and there's bound to be consequences down the line. Here is a screenshot to help clarify my issue http i.imgur.com ivSmhKe.png |
0 | Need help accessing booleans from other script Unity3D I'm making an endless runner game where platforms move towards the player so it makes it seem like the player is running across them. I'm trying to make it so that when the player dies, the platforms stop moving. What I have isn't working, when the player dies, the platforms just keep moving as if nothing has happened. Here is the script I have that is attached to the player using System.Collections using System.Collections.Generic using UnityEngine using UnityEngine.SceneManagement public class CoinColliderScript MonoBehaviour void OnTriggerEnter(Collider target) if (target.tag quot Enemy quot ) StartCoroutine(Died()) IEnumerator Died() PlatformMover.dead true gameObject.GetComponentInParent lt Animator gt ().Play( quot Male Died quot ) yield return new WaitForSeconds(0.5f) SceneManager.LoadScene( quot MainMenu quot ) Here is the script I have that is attached to the platforms using System.Collections using System.Collections.Generic using UnityEngine public class PlatformMover MonoBehaviour private Vector3 newPlatPos public float platMoveSpeed public static bool dead public void Start() dead false void Update() if (dead) newPlatPos new Vector3(transform.position.x, transform.position.y, transform.position.z) else if (!dead) newPlatPos new Vector3(transform.position.x, transform.position.y, transform.position.z platMoveSpeed) transform.position newPlatPos New Code Attached to platforms public class PlatformMover MonoBehaviour private Vector3 newPlatPos public float platMoveSpeed void Update() if (!CoinColliderScript.Dead) newPlatPos new Vector3(transform.position.x, transform.position.y, transform.position.z platMoveSpeed Time.deltaTime) transform.position newPlatPos Attach to player public class CoinColliderScript MonoBehaviour private static bool dead false public static bool Dead get gt dead set dead value print( quot 'Dead' changed to quot value) void OnTriggerEnter(Collider target) if (target.tag quot Enemy quot ) StartCoroutine(Died()) IEnumerator Died() dead true gameObject.GetComponentInParent lt Animator gt ().Play( quot Male Died quot ) yield return new WaitForSeconds(0.5f) SceneManager.LoadScene( quot MainMenu quot ) |
0 | How to create a re usable layout of text fields that can be bound to in world space? Current tools Unity 2020.3.2f1 (Win10) UI Builder preview package My end goal is to do the following At varying intervals, change values for many data objects in the background, such as prices, resources, demand, supply, etc. Display those values in a flat table list (as they change) in world space to the player, e.g. on a TV screen (or a transparent panel hovering above it, etc.) Have the ability to apply that layout (and its bindings) to another world space object of a different size, e.g. on a smaller or wider TV screen Imagine an office with 15 desks, all with 3 monitors showing the same data feeds and changing statistics, except the monitors were all different shapes and sizes. How could you avoid building all 45 monitor layouts individually, and binding to each field separately? So my question is What is the quot right quot way to build a re usable UI (ideally with UXML USS), display it in world space, and have the ability to update the text in that layout? I thought that UI Builder UXML USS would be the answer, but I am having trouble parsing how my end goal would be accomplished using that (or if that is even an appropriate use case for UI Builder). Fields that are displayed using UIDocuments are not exposed in the Hierarchy, and can't be dragged onto a script's input in the Inspector, for example. I'm able to project a UXML USS layout onto a texture gt material gt object, but I'm not sure how to bind to the fields within the layout The screenshot above is my latest attempt, a POC of a live timer (on the right) manually being updated (using a TextMeshPro field, works great), and the yellow panel to the left is a UXML USS layout pasted onto a texture material that's applied to a panel (in a canvas). On the far left is that same layout being used as a HUD, just to confirm it works the same as the floating panel. In game, this data will not be part of the HUD, it will only be in world space. As a POC, I have been trying unsuccessfully to get the timer value from the gray panel to bind to the quot should be time quot text in the UXML. So, should I just bite the bullet and build each layout by hand using game objects (such as in the gray panel)? Or am I halfway there with the UXML and just misunderstanding how UIDocuments work? Or is there a new smarter way of doing this I haven't heard of yet? Not looking for a full code example or anything, just a push in the right direction. |
0 | Left Hand and Right Hand Coordinate Systems In Blender and other 3D modeling tools, the coordinate system is right handed, while in Unity 3D and Orbiter Space Flight Simulator, they are left handed, why this could happen? Why they don't simply use the right hand coordinate system all the time to make things easier? Why don't all programs that deal with 3D graphics use Z as up? Y Z ZX YX RIGHT HAND LEFT HAND TOP VIEW TOP VIEW (fortunately, Unity3D converts from Blender coordinate system to Unity3D coordinate system) |
0 | Rotate object always at same speed on screen, no matter camera distance? I am rotating a globe like XCOM's hologlobe, I rotate it using Quaternion.RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta). I found a good value for maxDegreesDelta, in my case it is 5.0f. There is a limit on how close or far the camera can be, let's assume clos is 1.0f and far is 2.0f. I want to be able to zoom into the globe, but obviously when I do, it rotates a bit too fast then. When zoomed out, rotation speed is satisfying When zoomed in, rotation is too fast, making it more difficult to manipulate And the problem is even more evident as game view size gets bigger, i.e. fullscreen. Using Mathf.Lerp and Mathf.InverseLerp, I've tried to make maxDegreesDelta and mouse delta proportional to the distance the camera is but it's hardly convincing. Note I rotate the globe, not the camera. Question How can I ensure object rotates at same speed on screen, no matter how close or far camera is ? Code (assumes there is a sphere of radius 0.5 at Vector3.zero and camera is positioned at Vector3.back) using UnityEngine using UnityEngine.InputSystem namespace Test2 public class GeoScapeController MonoBehaviour region Public public Transform TargetObject public Camera TargetCamera Range(0.01f, 1.0f) public float Sensitivity public bool Smooth public float ZoomDistanceMin public float ZoomDistanceMax endregion region Private SerializeField HideInInspector private Quaternion TargetRotation SerializeField HideInInspector private int ZoomLevel SerializeField HideInInspector private int ZoomLevels SerializeField HideInInspector private Vector3 ZoomVector SerializeField HideInInspector private Vector3 ZoomVelocity private void Reset() Sensitivity 0.05f Smooth true ZoomDistanceMin 0.625F ZoomDistanceMax 1.25F ZoomLevels 10 private void Start() TargetRotation Quaternion.LookRotation(TargetObject.forward, TargetObject.up) ZoomVector TargetCamera.transform.position private void Update() var mouse Mouse.current var delta mouse.delta.ReadValue() var scale new Vector4( 1.0f, 1.0f, 1.0f) var x mouse.leftButton.isPressed ? delta.y scale.y Sensitivity 0.0f var y mouse.leftButton.isPressed ? delta.x scale.x Sensitivity 0.0f var z mouse.middleButton.isPressed ? delta.x scale.z Sensitivity 0.0f var r Quaternion.AngleAxis(x, Vector3.right) Quaternion.AngleAxis(y, Vector3.up) Quaternion.AngleAxis(z, Vector3.forward) if (Smooth) hopefully, quaternion limits won't be crossed ! TargetRotation Quaternion.RotateTowards(TargetRotation, r TargetRotation, 2.5f) TargetObject.rotation Quaternion.Slerp(TargetObject.rotation, TargetRotation, Time.deltaTime 5.0f) else TargetObject.rotation TargetRotation r TargetRotation var wheel (int) mouse.scroll.ReadValue().y 120 if (wheel ! 0) ZoomLevel Mathf.Clamp(ZoomLevel wheel, 0, ZoomLevels) var lerp1 Mathf.InverseLerp(ZoomLevels, 0, ZoomLevel) var lerp2 Mathf.Lerp(ZoomDistanceMin, ZoomDistanceMax, lerp1) ZoomVector Vector3.back lerp2 TargetCamera.transform.position Smooth ? Vector3.SmoothDamp(TargetCamera.transform.position, ZoomVector, ref ZoomVelocity, 0.3f) ZoomVector endregion |
0 | How to start in animating my model? I got a model from TurboSquid. Which is an archer and when i imported the model I got all the textures to be put on properly. The thing is the actual character has no children nodes, is it possible to still animate this model. I have looked throughout the files and there are a bunch of textures, but I don't happen to see any animations. Along side that the asset comes with an Avatar, I looked on the docs and still a little confused as to what that is about. If I cannot animate this model how could I force it to animate somehow or how could I make my own model. I am not a artist at all and just focus on the gaming logic and and programming, and I am working solo. Just wondering what are some options to get a game up and running with some decent graphics. So, far I use the model to get the game play down, but now I want to make it visually appealing. |
0 | Creating a static 2D background at runtime I'm using unity for a 2D game. We have a lot of props for grass, plants, flowers, etc that are static and always in the background. I'd like to optimize the background and reduce the drawcalls as much as possible by making a big image with the final result of the background. The idea would be to draw on a texture all the elements in the background, and then use this texture as the background. This way a single element has to be drawn. How can I create these background texture at runtime, so it is generated as soon as the scene is loaded? |
0 | WWWForm .AddField vs .headers I am using WWWForm to do the equivalent of GET and POST from python. To add headers to my unity requests, according to the documentation I could two options WWWForm form new WWWForm () form.AddField("user", username) OPTION 1 https docs.unity3d.com ScriptReference WWWForm.AddField.html form.headers "user" username OPTION 2 https docs.unity3d.com ScriptReference WWWForm headers.html With the risk of asking a very naive question Can someone explain the difference between the two? Thank you |
0 | Calculating size and position of Tilemap for camera bounds I'm new to Unity and I'm following a series of tutorials covering off building a 2D Zelda like game. I'm at a stage where I have two Tilemaps side by side and I'm working on a transition between them, triggered when the player collides with a trigger at the edge of Tilemap 1. I have a basic camera movement script which follows the player and constrains the camera within the bounds of Tilemap 1 it's constrained by two Vector2 fields (a min and a max). I got the values for these two Vector2 fields manually in the Scene editor by moving my camera to the desired edges, noting its transform position and entering in those values to the camera movement script. For the transition, I will change these min and max Vector2 values in the camera movement script to then constrain the camera to Tilemap 2. I could just hard code these in again, but it seems like a good learning opportunity to try and calculate these values dynamically. My room change script stores a reference to the camera movement script so that it can amend the min and max values itself. In an attempt to get it to calculate the next room's bounds dynamically, I added a public Tilemap field to the room change script so it can examine it and determine the bounds of the next room itself. I then set this field in the Inspector to point to Tilemap 2. I've so far been unable to calculate these new bounds from the Tilemap reference. The cellBounds property looked promising Position ( 44, 7, 0), Size (19, 20, 1) the size is right, but the actual origin position I calculate manually by moving my camera in the scene editor is 35.14, 2.02. As a result, setting the bounds off of what cellBounds tells me does not work. I've made sure that I've used the 'Compress Tilemap Bounds' too. I've tried accessing individual tiles within the Tilemap and using CellToWorld this only seems to give me the Tile's position relative to the Tilemap (?). The transforms for all of the Tilemaps in my scene and their parents (which are Grids) are set to 0, 0, 0. Basically, I know I should calculate a value of approximately 35.14, 2.02 for my new min position, but I can't see any way to calculate that. How do I go about achieving this, and the same for max? Here is what my scene looks like Main Camera Camera, Audio Listener, Camera Movement (script) Player Sprite Renderer, RigidBody 2D, Box Collider 2D, Player Movement (script), Animator Room1 Grid Ground Tilemap, Tilemap Renderer Collision Tilemap, Tilemap Renderer, Tilemap Collider 2D, RigidBody 2D, Composite Collider 2D Room2 Grid Tilemap Tilemap, Tilemap Renderer RoomTransfer Box Collider 2D, Room Move (script) |
0 | Check whether an object is fully inside overlapped by other objects in Unity3D? I have structures made of voxels (cube gameobjects), and I want to make complex structures from them. But I don't always want to place them on the grid. I want them to be more realistic, like diagonal (Don't mind those visual artifacts) (If I would want to make a fortress like this on the grid, these diagonals would be ugly and zigzaggy.) My problem is that due to this there would be double the voxels at the overlapping places. I want to remove every cube (for example from the selected wall object) which are being FULLY overlapped. This way there won't be double voxels (only partially at the edges, which is fine) and it would look good as well. How could I check this? I don't want to modify the structures manually because both the angle and the other object may vary, thus one structure would need lots of variations. |
0 | How to reproduce this (parallax?) effect? I'm wondering how to imitate the camera movement like in the gif below. It s from a Android game. This game for example (via GIPHY) Actually, I am not sure if this can be called a parallax effect, but it is the only word I can think of. My code until now using System.Collections using System.Collections.Generic using UnityEngine public class RotateAroundTarget MonoBehaviour public Transform target The object to follow public Transform background public Transform foreground public float speedMod 20.0f Camera speed public float topMargin 0.2f Top rotation margin The position of the target private Vector3 point Point if the camera is rotating to the left private bool toLeft false Use this for initialization void Start () point target.transform.position transform.LookAt (point) Update is called once per frame void Update () The camera is moving to the right until it reaches the top margin, then it changes it movement direction if (!toLeft) transform.RotateAround (point, new Vector3 (0f, 1f, 0f), Time.deltaTime speedMod) rotateBackground (1) rotateForeground ( 1) Debug.Log ("Izquierda") if (transform.rotation.y gt topMargin) toLeft true else transform.RotateAround (point, new Vector3 (0f, 1f, 0f), Time.deltaTime speedMod) rotateBackground ( 1) rotateForeground (1) Debug.Log ("Derecha") if (transform.rotation.y lt topMargin) toLeft false Direction 1 (left) 1 (right) public void rotateBackground(float direction) background.transform.Rotate (new Vector3(0, Time.deltaTime (speedMod 2) direction, 0)) public void rotateForeground(float direction) foreground.transform.Rotate (new Vector3(0, Time.deltaTime (speedMod 2) direction, 0)) But what I obtain in Unity Editor is this Result in Unity Editor (via GIPHY) Any suggestion on how to get this? Any help would be appreciated. |
0 | Issue Implementing Ads with Vungle I'm trying to implement ads on Unity for my program with Vungle, I followed the implementation guide at https support.vungle.com hc en us articles 360003455452 reference sample app 0 3 But the ads aren't displaying at all. I get a debug.log that seems to indicate the ad was called, but no ad displays, even if I build and run the program. I contacted support, but they haven't been super helpful. They told me to wait a little longer before calling the ad, I put it on a coroutine with a 10 second delay and still no ad. Here's my script for reference, using System.Collections using System.Collections.Generic using UnityEngine public class VungleAds MonoBehaviour string appID string iosAppID quot ios app id quot string androidAppID quot android app id quot string windowsAppID quot 5fbfc6bc1136b9069f63f0bf quot void Awake() appID windowsAppID Vungle.init(appID) private void Start() StartCoroutine(ShowBanner()) Vungle.loadBanner(appID, Vungle.VungleBannerSize.VungleAdSizeBanner, Vungle.VungleBannerPosition.BottomCenter) IEnumerator ShowBanner() yield return new WaitForSeconds(3) if (Vungle.isAdvertAvailable(appID)) Vungle.showBanner(appID) else print( quot No ad quot ) StartCoroutine(ShowBanner()) It's just printing quot No ad. quot repeatedly. Does anyone have any experience with Vungle ads? I have been trying to figure this out for like a week haha. Thanks |
0 | How to make collisions occur between objects using the same script? Well what I m trying to do is have cars travelling on the road. The cars have a trigger at the front and a hitbox at the back of the cars. What I want to happen is when the trigger hits the hitbox it compares the Variables for speed of the two cars in the collision, i.e. the make the car at the back slow down or equal the speed of the car in the front. However, what I am having trouble with is referencing the speed of both cars and comparing them. This is due to them both being prefabs using the same script. Which I m learning means that I m just referencing the same script and not the actual values of the individual car. But how could I get round this? Is it possible to have collisions occurring between objects using the same script? private void OnTriggerStay2D(Collider2D collision) Debug.Log("TriggerStay") GameObject collidedParent collision.gameObject.transform.parent.gameObject get parent transform and then its gameobject Traffic Col speed collidedParent.GetComponent lt Traffic gt () if (speed gt Col speed.speed) Accelerate false ApplyBreak true else if (speed lt Col speed.speed) Accelerate false ApplyBreak false speed Col speed.speed if (transform.position.y gt collision.transform.position.y) turn turn 1 Debug.Log(this.gameObject.name "someMessage") if (transform.position.y lt collision.transform.position.y) turn turn 1 Col speed.turn 0 Debug.Log(this.gameObject.name "someMessage") private void OnTriggerExit2D(Collider2D collision) turn 0 Accelerate true ApplyBreak false |
0 | Aligning cube faces Unity I am using a shader that uses a gradient noise node and time to add a wavy effect to a grid like texture. The issue with doing this is that it causes the lines to be misaligned on the different faces of the cubes. What I would like is for the lines to be conjoined, like this (wavy effect not applied) The shader graph layout I am using to generate this effect is How can I go about fixing this issue so that all the lines are conjoined, but also have a wavy effect over time? Edit A rough sketch of what I am after. Here the black dots represent the physical shape of the object and the lines should be able to wave around the whole object and all be connected, regardless of whether there is an edge there or not. |
0 | Character movement in Unity For an endless runner game such as Subway Surfer, in order to move your character so smoothly in both z axis and x axis, which component of the followings is better CharacterController or RigidBody? Can we use both of them together if so, will it have any effect on the performance of our game? |
0 | How can one achieve the mechanic of hitting cars or bumping into them like in Burnout games' takedown modes? In Burnout games there's this game mode where the player can trash other cars by bumping into them or bumping them into walls. As you can see in this video link This is known as a takedown. I'm working on a racing game and I would like to work on a similar feature. I added a bouncy material to my cars collider in hopes that this effect would be replicated to some degree but all it did was to slightly push the cars away from the player. I don't have that much experience in making games so I'd appreciate any help I could get about the subject. |
End of preview. Expand
in Dataset Viewer.
This is the data used in the paper Large Language Model as Attributed Training Data Generator: A Tale of Diversity and Bias. Checkout the paper: https://arxiv.org/abs/2306.15895 for details.
label.txt
: the label name for each classtrain.jsonl
: The original training set.valid.jsonl
: The original validation set.test.jsonl
: The original test set.simprompt.jsonl
: The training data generated by the simple prompt.attrprompt.jsonl
: The training data generated by the attributed prompt.
- Downloads last month
- 60