Tag Info

Hot answers tagged

3

I'm doing research in autonomous navigation for robotics, and this is a familiar problem. The real world analogy is you have two vehicles (a robotic motorcycle and a robotic tank) that have to decide on going through a narrow alleyway or not. Dimensions and positions are known by whatever means (radar, LIDAR, maps, GPS, etc)--how do you program such a ...


3

You've got the moving part right but the rotating adds a significant amount of complexity to the problem. Luckily, you can hack in rotational velocity with a formula mentioned here. It approximates rotational velocity based on the distance from the center of mass to the point of contact, and the positional velocity. Here's an implementation: a = (cp.x * ...


3

I wrote a camera script that auto-zooms based on a transform's position and scale. Attach the script below to your Camera. Then, create a GameObject, and set its position and size. Then link this gameobject to the "Area" public property of this camera script. The "Area" GameObject can be adjusted at runtime, and should provide you with a mechanism to at ...


2

float YOffset = 0f; void Update() { myTransform.LookAt(target); float targetPosY = target.transform.position.y + YOffset; if(myTransform.position.y != targetPosY) { float MoveAmount = moveSpeed * Time.delta; if(Mathf.Abs(myTransform.position.y - targetPosY) < MoveAmount) myTransform.position = Vector3.up * ...


2

I think the amount of entities is the best to test that and to keep things simple just multiply them. Simply add a script to your barrel prefab which will wait 1 second after start and then spawn two more entities of the same object. Add some force to push them away. That way you only have to place one instance on your screen, start your game and wait a ...


2

I would suggest procedurally spawning the object constantly, and adding mesh colliders. Mesh colliders are very cpu intensive, and if you have a script that continuously creates these barrels, it will keep doing so until you kill unity. You can also track your gameplay statistics by clicking on the stats button up the top of your game window.


2

Here are some answers to your questions: 1) If you want your sprite sheet to be compressed (which will reduce memory usage, at the cost of some quality), you will want it to be a power of two. If you are going to do completely uncompressed textures, then any size is OK. My recommendation is to stick with the power of 2, since that gives you the flexibility ...


2

The default sprite filter mode in Unity is set to Bilinear. If you change it to Point, it will retain the pixel crisp. http://docs.unity3d.com/ScriptReference/FilterMode.html


2

The default sprite size in Unity is 100 pixels per unit. This means that if you have a sprite that is 100 pixels wide, it would occupy "1" Unity unit. If you moved this sprite to the left by 1 unit, it would shift 100 pixels to the left. You can change this value by selecting your sprite, and changing its "Pixels per Unit" property. I typically set my ...


1

Looks like you're mixing 3D & 2D physics. You're using OnCollisionEnter2D, which triggers when 2D colliders hit each other. But then you're using Physics.Raycast, which casts rays against 3D colliders - so it won't be able to detect the two colliders that triggered the event, or any similar colliders in your scene. Maybe you want Physics2D.Raycast?


1

Please take note that the question was unclear and changed meaning 3 times, hence the 3 answers in one How can I verify that a given size is a multiple of another? This is a very good case to use the Modulo operator. Let's say you have a texture tex with size (width, height). Now you want to render the texture with size (drawWidth, drawHeight) on the ...


1

Having done both, I can say that using a single quad is best in circumstances where none of your larger objects take up more than one grid square and/or are square/cube-shaped. Otherwise, you will eventually run into Z-sorting issues. The multiple-quad solution was the best one that I found to deal with that particular situation. IE, if you had larger, ...


1

You need to specify the width and height when you draw the texture. batch.draw(texture, x, y, width, height); In your case you want to set the width and height to one since one wall tile is one world unit big. Because you don't specify a width and height the batch uses the width and height of the texture. That is why it covers 16 world units instead of ...


1

finicky and broken feeling This should probably just be the issue because you're using FixedUpdate() instead of Update(), thus the groundcheck / jumpcheck, doesn't happen every frame, but every physics update, try changing that and it should be fixed.


1

Sample code to move an object up and down. public float Y_Min = -100f; //Set this to the lowest Y value you want the Item to move to. public float Y_Max = 100f; //Set this to the highest Y value you want the Item to move to. public float VerticalSpeed = 5f; //Speed the Item will move vertically. public float Dir = 1f; //Direction the Item is moving, either ...


1

You can use Mathf.Lerp. Mathf.Lerp takes in 'From', 'To' and 'T' parameters. It interpolates your value From to To over T. The T parameter should be a value between 0 and 1. 0 is equal to your From value and 1 is equal to your To value. For example: From = 1 To = 2 Difference = To - From = 1 So if T were equal to 0.5, the returned value would be 1.5 ...


1

If you load your sprite sheet in programmatically: private Sprite[] Sprites; .... Sprites = Resources.LoadAll<Sprite>("SHEET NAME"); The Sprite object has a name property, which you can then use to retrieve a specific sprite by name: public Sprite GetSpriteByName(string name) { for (int i = 0; i < Sprites.length; i++) { if ...


1

What's Happening This is completely accurate physical behaviour, which can be explained using a free-body diagram and a little high school physics1: The mass of the block is m and g is the gravitational constant. Fa is the applied force. To understand why the block is not moving, we can write out the force balances in the x and y directions. x-Momentum ...



Only top voted, non community-wiki answers of a minimum length are eligible