New answers tagged

0

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


-1

GameObject bulletInstance = Instantiate(bullet, transform.position, player.transform.rotation) as GameObject; bulletInstance.GetComponent ().velocity = transform.right * bulletSpeed;


0

Add some random points Repell points located too close to each other Add some points along the edges Do Delaunay Triangulation on all the points Done


-2

This code is adapted from a game demo in 'Cocos2d-x by Example Beginner's Guide' by Roger Engelbert. circleSprite->setScale(0.1f); circleSprite->runAction(ScaleTo::create(1.0f, 5.0f)); First it makes the sprite tiny (0.1f) and then runs an action to scale it up over 1.0 second (I have used an arbitrary scale to value of 5.0f for this example). The ...


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


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


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


0

I'm not sure if this is the way that that game specifically did it but what you do is create a texture which is then subtracted from other textures. So in this can you create a shape which represents the whole in the ground, then you when the bullet explodes it subtracts the shape from the ground texture and leaves a whole in the ground texture. When you ...


0

You can just draw holes over the floor object, here all the holes have their own class with separate properties from the floor class:


0

I've solved the problem after a bit more analysis. In addition to the suggestion by spectacularbob, I forgot about a line of code that applies damping to the players velocity to make him slide less. This worked well for movement on the x-axis, but resulted in the jittery jumping on the y-axis. I simply changed the following: ...


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


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


0

You can make the shadow by simply parenting a Sprite with a black circle and adjusting it to be below the ball so that when ball moves this Sprite moves and it looks like shadow. The 3D effect by changing scale depending on the depth or use triggers to shrink it on entry.


0

The game is either doing some trickery to achieve a 3D like trajectory (sine waves, parabolas, etc) or using actual 3D math. Then, they simply take the 3d coordinates, and render the ball larger or smaller depending on the depth. Essentially rasterizing. Shadows are achieved either again with 3d math by projection or simply faking it again with a simple ...


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


0

I would just cheat and use the formula for a parabola. The ball sprite can be sized based on the height of the parabola.


0

Transform them in software using the CPU and give the GPU only the final vertex coordinates. The savings in bus bandwidth by reducing the VBO size will be greater than the cost of the transform on the CPU which can be greatly simplified by combining the sprite expansion and transform into a single step, no heavy matrix multiplication needed. 2D rotation, ...


0

I'm a beginer in pygame and python so i'm having some troubles hahahahah. I figured ou what my problem was. Pygame does not reognize two keys being pressed or released at the same time. So for example, when i press the down button, and the right button the program states that self.down_is_down = True and self.right_is_down = True so the player gain a ...


0

you could just move the transform.y up n number of times until the feet are on the ledge and forget the physics temporarily, i think it will work fine, you can always measure the distance between falling objects and the player in case collision fails during a transform translation. to make sure a collision occcurs..


-1

why not set triggers that say.. ok the block is close enough.. turn off the rigid body and lerp it over the opening then drop down my increments until its in a desired position?


0

If you remove the part bellow, maybe it can work. I do this in the JavaScript game and worked, try it: if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.left_is_down = False if self.right_is_down: self.speed_x = self.velocity else: self.speed_x = 0 if event.key == pygame.K_RIGHT: ...


0

From the poor information you shared, the only thing that comes up to my mind is that you are using a Rigidbody instead of a Rigidbody2D.


0

I'm going to assume that both has a ridged body attached to them. void OnCollisionStay2D(Collision2D other){ if (other.transform.tag == "MovingPlatform") { Gameobject.GetComponenet<RidgedBody>().velocity = Gameobject.GetComponenet<RidgedBody>().velocity; } } Ok, this should make the character "stick to the platform", You might ...


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


0

So from what I understand you want to shoot using OnTouchDown(), well if thats what you want to do then you simply repeat what you did in the playerController class. ShootingScript: public GameObject shootingBullets; // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.Space)) { Instantiate(shootingBullets, ...


3

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


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


0

No. As far as i know, Unity is only made to use JavaScript and C#.


-3

My suggestion is to start using a graphic engine such as Unity or Unreal Engine, mostly because they are the most famous and there are plenty of tutorials and already know issues/solutions. C# can be used as a scripting language in Unity. UE requires c++.


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


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


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.


0

This question on partial path-finding presents one solution - modify your path finding algorithm to remember the node visited that had the closest estimated distance to the target. Eventually, the path-finding will fail to get a route to the target (since it was unreachable), but you will have a path to the closest point encountered while it searched.


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


-2

You can use a coroutines for this task, you should call this coroutine in order to damage you player, so you can set a time of invencibility with the waitForSeconds(3f); function bool finishedCoroutine = true; void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")) { { if(finishedCoroutine){ ...


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


-2

Use a bool variable to make sure you only enter the if once, then reset it after you have left the trigger. Or dont reset it if it has to happen exactly once. void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")&&!isDamaged) { currentHealth = -5f; ...


-2

Create a collection and store a reference of the GameObject once it enters and remove the reference once it exits. For example, here I am utilizing HashSet. using System.Collections.Generic; private HashSet<GameObject> takenDamageFrom = new HashSet<GameObject>(); void OnTriggerEnter2D(Collider2D other) { // If damager and not yet damaged ...


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.


-3

I'm going to give you a rather stupid answer but what the heck. First of all hundreds of objects in a game is no problem. Secondly there is this guy called quil 18 that has great tutorials. Start with the Basics of 2d tile maps and then you can watch this gigantic series about a base building game here


3

I guess what you're looking for is what's called "Worley's Noise". https://aftbit.com/cell-noise-2/ It's very similar to what you're already doing. But instead of placing the points at the corners of the grid and moving them around, you place one (or more) points within each cell at random. When you want to find the closest point to a point P, you find ...


1

It isn't that clear what you mean with top and height, but let's say you have your character's x, y, width and height, and so you do for the wall (assuming the x and y values are on the top-left corner of the character/wall, and the y axis gets greater when going downward) if (character.y + character.height > wall.y && charcter.x + ...


0

Create a Ui Button at runtime, Working example without prefabs. public static UnityEngine.UI.Button UiTexturedButton(Sprite sprite, Vector2 size, GameObject canvas) { GameObject go = new GameObject("Textured button (" + sprite.name + ")"); Image image = go.AddComponent<Image>(); image.sprite = sprite; ...


0

Take a look at this overload of the SpriteBatch.Draw() method. What you want to do is have the origin argument be a Vector2 with its x-coordinate set to half the width of your final image (and whichever y-coordinate you feel is appropriate), and increase the scale argument from (0,1) to (1,1) over the course of time it takes to "unfold" the paper. Since ...



Top 50 recent answers are included