Hot answers tagged

9

I came back to this today and after some more investigation and trial and error I discovered that the culprit was targetTexture. With some more investigation I learned that reading and writing to the same texture in a shader is bad practice (not surprisingly) and will cause undefined behavior on GPUs. The solution was to copy the target texture to a new ...


4

Based on my comment, here is what I'd do: Upon detection of the circle and the corner (this will be, IMHO, the most complicated thing to do), take the angle of the line segment between the centre of the circle and the corner (in RED), calculate the perpendicular to that (the tangent, in BLUE), and have the vector in (PURPLE) be reflected to the vector out ...


3

IEnumerator OnCollisionStay2D(Collision2D col) { if (col.collider.CompareTag ("Player") && canAttack == true) { player.Damage (enemyDamage); canAttack = false; yield return new WaitForSeconds(3); canAttack = true; } }


3

According to the Unity documentation for OnTriggerEnter2D the trigger is "[s]ent when another object enters a trigger collider attached to this object (2D physics only)". The function should only be called once per entrance. You could gather further data by logging the number of calls to OnTriggerEnter2D and OnTriggerExit2D. Perhaps some funny business is ...


3

Unity remote sends a compressed stream from the editor to your phone and then sends back the inputs from the phone to the editor. there is nothing you can do about it being bad quality. How ever this does not represent the final quality of the build. Try making a real build for android and check how it looks then.


2

As it says on the SDL documentation, SDL_GetKeyboardState returns an array of the keyboard state, with SDL_SCANCODE values as indices. You can't use the SDLK_ values, they won't reference the right values. So change your code to use the SDL_SCANCODE values. There is a reference page here. Your if-statement should then look like if ...


2

When you have 2d sprites in a 3d environment, they work like two-dimensional planes. Think of them as cardboard-cutouts which are moving through the world. When you want to rotate these cardboard cutouts to always face the camera, then the search term you are looking for is "Billboarding". It can be implemented by attaching this MonoBehaviour to it: using ...


2

Here's one of my go-to jump functions. It's similar to a Mario jump - fast at first, slowing down until reaching the top. Please excuse the syntax. I haven't used C++ in ages, and never SFML. const float GRAVITY = 9.0f; const float MAX_VELOCITY = -10.0f; const float MAX_AIR_TIME = 1.2f; float timeInAir = 0.0f; float jumpImpulseTime = 0.2f; float ...


1

Unfortunately - No. Unity only supports: UnityScript (JavaScript for Unity) and C#. Boo support dropped in Unity 5. But C# is very similar to Java, and I for myself started only with Java knowledge and it was no problem for me to learn C#.


1

You are fixing the time to 10(seconds?), so it will always takke it 10 seconds to reach its target. So if its a short distance, the bullet will move very slow and over a long distance the bullet will move very fast. So you need to set the time to (distance)/(velocity).


1

Yes. It is possible. Any of the scene2dUI widgets, like Table, inherit from Actor. Actor has a setVisible(boolean isVisible) member that will hide it and all of its children and disable any touch events to it. You just have to make sure that your menu or game instructions are in front of your Game view by adding them to your Stage last. You will also need ...


1

You should probably take a look at Scene2D's Window class. Think of it as a screen that just overlays other screens. It's also a Table, which means you can add buttons or any other Actor to it just like any other table. This also means you can directly add it to your Stage, if you wish. A simple pause screen would be something like this: Window pause = new ...


1

My guess to why it is choppy is because scl() is permanently scaling your velocity by deltaTime each update call. Since deltaTime varies a little from frame to frame, this causes the choppiness. Change the position update to float velocityX = player.getVelocity().x; float velocityY = player.getVelocity().y; player.getPosition().add(velocityX * ...


1

You can achieve the effect of the ball by modifying two things: 1. The game object's size. Whenever the ball is kicked modify it to match the specific action, like a long lobbed pass will make the ball bigger. 2. The texture that is being applied to. Make the texture repeat itself on the direction it is going. For example a forward pass will make the ...


1

An alternative solution to using the coroutine system is to store the time when the object attacked last in a private variable and compare it to the current time: public class Attacker : MonoBehaviour { private float lastAttackTime; private const float ATTACK_DELAY = 0.1f; // 10 attacks per second void OnCollisionStay2D(Collision2D col){ ...


1

The easiest way would be to use the Invoke command. void OnCollisionStay2D(Collision2D col){ if (col.collider.CompareTag ("Player") && canAttack == true) { player.Damage (enemyDamage); canAttack = false; //wait 3 seconds or so Invoke("EnableAttack", 3f); // Invoke will call a given function after the time given ...


1

Modifying the velocity will interfere with your physics if you're not sure of what you're doing. Ideally, you'd move things around by adding forces. Using Rigidbody2D.AddForce is the least complicated way to move objects that have a RigidBody.


1

I would recommend you to place the 2d sprite not in the game world but instead place it on a UI canvas with "Screen Space - Overlay" mode. You can convert the game-world position of a GameObject to screen-coordinates using Camera.WorldToScreenPoint. Then you need to convert the screen coordinates to canvas coordinates and place your sprite there. Code ...


1

I've been thinking about this problem for a long time and looked at some of the answers here and on other forums. I came up with the following idea: Suppose the circle has radius R. When looking at cases where the circle collides with the AABB , the center of the circle has to fall within a certain area around the AABB. The extreme cases are when the center ...



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