Tag Info

New answers tagged

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?


0

To understand my proposal you will have to stop thinking in tiles for a while, even if your finished game needs to guarantee that all objects will be tile aligned. I suggest you to adopt the same design I'm following for my current project. Position your objects in 3D, they have x,y and z. In my case, x is positive to the right; y is positive upwards; z is ...


0

I read your question as can you use C++ to make 2D games in Unreal, to which the short answer is yes. Some key points to bear in mind: Everything you can do in blueprint, you can do in C++. So if you feel more comfortable in making your game in C++, it is fairly straight forward to follow blueprint tutorials and implement them in C++. A few bits and pieces ...


0

Blueprints are designer-friendly, so that you can introduce code-like behaviour from a friendly interface without actually writing code. Mind you, you can use C++ to achieve the same goal. When you write your C++ code, you can add some macros (UE tutorials show how) in your code to make it "visible" as blueprints. It's not an advertisement; it's a really ...


0

Take a Look at Texture2D.GetPixel You can find the contact point on the collider and then map that to the specific point on the texture.


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 ...


0

Managed to fix this by using Viewports when drawing the Rectangles / Cameras GraphicsDevice.Viewport = new Viewport(_level); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _camera.ViewMatrix); DrawLevelTiles(); spriteBatch.End(); GraphicsDevice.Viewport = ...


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, ...


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

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 ...


0

In this answer I assume you are using C++ Object Oriented Programming. If you are using another language, then hopefully you are still able to make use of my answer. Do what drumbumLOLcatz said, and do collision detecting. This link has some good examples in JavaScript, which is easy enough to understand and convert to any other language. And a quick ...


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.


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 ...


0

What I have found is that is good to make a handler class that has a list of GameObjects and draws, ticks(update) and can add new objects. ex: import java.awt.Graphics; import java.util.LinkedList; public class Handler { public LinkedList<GameObject> objects = new LinkedList<GameObject>(); private GameObject temp; public void tick(){ ...


0

It is not necessarily a better way to have a separate class to draw your entities. It is just one way how to implement how your entities get drawn. But to answer your question. One way could be that each of your entities give access to the the data which are necessary to draw a entity. As soon as your entity provides such function then your rendering ...


0

By using raycast, you can accept touch gesture per layer (see unity Raycast documentation). I think it's better to put panning object and your sprite on different layer. Then you may check for raycast colliding with your panning object and sprite. I think it's better to use different touch gesture, like tap for interacting with sprite and sliding fingers ...


0

With r being the circular area view radius; Make a mesh that covers the polygon where the nodes are at most 2r apart and connect the nodes with neighbours. Based on the distance and wind/water current between each node, add a difficulty value to progress through the arcs; arcs are bi-directional and don't have the same value (for instance for node A to B ...


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


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 * ...


0

From what it seems, you are approaching your problem backwards :) The first problem you are facing is that you try to give an physics object, that is kicked by something else, a hard-coded trajectory, which means exterior influences (the kick) will not make it move. Instead, you could implement the gravity simulation from the second problem first. Then, if ...


0

Could it be that the quality setting in Unity affects the maximum texture size, and that your player sprite is part of a larger texture than the texture that contains the tiles?


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.


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 ...


0

An possible algorithm, expsed in python language: def get_distances_for_points(object_position, max_distance): points_distances = {} points_to_looks = [object_position] for current_distance in range(max_distance): new_points_to_looks = [] for looked_point in points_to_looks: around_points = <here return around ...


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

Chris Hecker has written nice article about rigid body dynamics. This article describes exactly what you are asking for. Link to the home of article: http://chrishecker.com/Rigid_Body_Dynamics Part 3 of this article talks about collision response: http://chrishecker.com/images/e/e7/Gdmphys3.pdf


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 ...


0

I found a similar question on the unity forum a while ago, this may be useful since you are not limiting how many times your character can move(it is not turn based therefore the controller you are using will no longer be waiting for an opponent to move it will behave oddly because when moving it will be called again and again without waiting and will cause ...


0

Zooming by setting the Z-Position. Obtain the Z-Position value by using transform.position.z, and then make a if-condition to declare when the different modes you would like to show. private float maxZoomIn = 5.0f; void Update() { zoom(); checkZoomState(); } void zoom() { //Simple zooming mechanics if(transform.position.z >= maxZoomIn) ...


0

The first clear issue is this line: transform.position += Vector3.right * acceleration * Time.deltaTime; transform.position is in length units (it's value represents distances along the 3 world axes from the origin). In this line of code you are adding a value with velocity units to a variable with length units. acceleration is length/time^2, Time. ...


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 ...


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 * ...


0

First of all, why have a private member "myTransform" and then mix usage of "transform" and "myTransform"? It is more readable to just use "transform". I have a feeling that the problem arises from using "myTransform.up" vs "Vector3.up" combined with your rotation code. I think the combination of the quaternion calculations and the local up vector is ...


-1

Did you try not to Destroy the object at the moment when you play the animation? wait until the animation is finished. i hope it helps!


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 ...


0

A major bottleneck here is syncing the CPU & GPU to shuttle the texture back and forth - to the CPU for modification with SetPixels(), and to the GPU for display. Also, the CPU is typically working on just one pixel at a time, while the GPU can churn through them in huge batches. So, we can often greatly improve performance by keeping the texture work ...



Top 50 recent answers are included