Good day! I'm a beginner developer, and I have a problem which is on the Russian-speaking forums have not been able to solve. The fact is that I have 2 objects are added to the edge collider2d and rigidbody2d. The collision of the objects they should not pass through each other. But unfortunately it does not work. If you add one of the objects of box collider2d everything works as it is necessary. Please tell me what could be the problem. thanks in advance.
↧
Two edge colliders
↧
Upgrading Unity to 5 threw off all 2d physics. Why? How to fix?
Was making a 2d platformer in unity 4.6 then upgraded to unity 5 and now my player and enemies seems to be slowly floating away. All the project settings are the same as before. Not sure exactly what other info in needed, let me know and I'll be happy to provide it.
↧
↧
When to use Effectors instead of scripting the behavior?
Performance wise or any other aspect, what are the scenarios that dictate the effectors as the right tool to use?
↧
How to change distance but maintain speed and height of jump
Suppose I have a block (RigidBody2d) traveling on a flat surface at a constant velocity to the right. The block jumps when the player presses the jump key, and the rigidbody has a force added onto it so that it jumps. What is the best way to change the amount of time that the block spends in the air moving up and "floating" down. E.G. it currently moves 20 units to the right when I press jump before landing, but now I want it to only move 10 units to the right. Additionally, the speed of the block and the jump height of the block should stay the same. The only thing changing is the distance traveled in the air.
Can this be done with the Unity2D physics engine?
↧
Optimal way to check repeatedly close objects
Hi,
I am developing simple flammable object. I have made it but i am having second thoughts on implementation.
I have flammable object that can catch fire.Every flammable object that is on fire cast every 0.1sec OverlapCircleAll to check its surroundings for other flammable objects so it can fire them up. This works well on static and dynamic moving objects.
It works fine but I am having second thoughts about performance impact on lets say 100 objects casting OverlapCircleAll.
Any ideas to improve performance or I should not bother ?
Thanks.
↧
↧
Ferr2d terrain physics material does not affect
I have sliding gameobject with polygon collider2D and two ferr2D terrains with different physic materials. First one have friction 0 and the second one 5. But when my gameobject slides throught/across those terrains, they both slow down the gameobject as much, so the friction seems to be the same in both. What's the problem here?
↧
How to detect what Gameobjects are in a Collider2D? (C#)
I am making a tower defense game (2D) and I am working on making the towers shoot the enemies. I want my turrent to shoot every 1 second and hit the enemy the closest to the front. My solution to this problem is by using circle colliders to detect if an enemy is in firing range, but I can not figure out how to shoot the enemy in first. I am stuck on trying to figure out how to put the enemies that are in the turrents range/collider2d in a list/enumerator/array (Whichever one is appropriate for storing gameobjects and can change length).
I looked through the documents and I couldnt find any collider2D function that lists the gameobjects in its range, so i need an alternative way to do it.
↧
Rigidbody2D is kind of flying instead of falling when the child box is colliding
Hi everyone,
I got a strange issue, everything is in the title, but i'll add some details :
I'm making a 2D side scroller game, the player can move on X and Y axes like in Castle Crashers. So the player has 2 objects : "**Body**" as parent which contains the **Rigidbody2D** and a **BoxCollider2D**, and "**Feet**" as **child** of "**Body**" which contains only a **BoxCollider2D**, which collides with some walls as you can see here :
![alt text][1]
When i press the jump key, the Y position of the "Feet" is stored, and a force is applied to the Rigidbody2D. During the jump, i set the "Feet" Y position with the one stored. On a normal behaviour it works fine, but if i go against a wall (as shown on the screen), during the jump, when the Body is supposed to go down, he flies (the body keeps a velocity of 0).
I guess the "Feet" collision breaks the "Body" Rigidbody2D stuff (i tried by adding a OnCollisionStay2D on the "Feet" object and it's returing true each frame).
Does someone knows how i can avoid that ? One solution is to make a "teleport" of 0.01f on top of the wall, but i would prefer to avoid this solution.
PS : i already have a Physics2D Material with 0 as friction on the player and the wall
PS2 : sorry for my bad english :/
[1]: /storage/temp/54440-bug-physique.png
↧
Ground Check Issue
So ive been following the 2d controllers tutorial and he was covering the groundcheck and falling physics. The problem im having is that when the player is not on ground, the ground boolean does check off but the groundcheck dont let the player fall off at all. Please help!
↧
↧
dropping series of masses connected by spring
I am trying to show how a series of 2D masses connected by string will fall. I have connected 10 masses with a spring joint. However they all fall at the same time. I would like to make the simulation such that their is initial tension and then the tension at the top is released so the bottom box does not fall until the rest of the masses have collapsed. Does anyone know how this would be done? What would I say in my script?
↧
How to see if two objects are touching each other
So, I am trying to check if two objects are touching each other, and this is the part of the script that I cant get to work
public static bool IsTouchingS (BoxCollider2D.StraightS, BoxCollider2D.PlayerCar);
void GetLocator ()
{
if (IsTouchingS == true)
↧
Trigger problem on devices
I have the following problem.
If i put an object with collider and animation, and dont use a rigid body, when i use OnTriggerStay2D the trigger registers without even the player touch the trigger.
If i put a rigidbody2D the object does not appear at all. or trigers other trigger objects on the level depend if i have kinematik on or off.
The game works fine at the editor, the problems appear when i build them for ios and android Devices.
I have Checked everything, object is with 2D Collider, is trigger is enable, i use trigger 2d code, and the rigidbody is for 2d.
↧
How to use Unity Terrain with 2D Physics?
[Unity's 2D Physics](http://docs.unity3d.com/Manual/Collider2D.html) are constrained to X and Y axes.
[Unity's Terrain](http://docs.unity3d.com/Manual/terrain-UsingTerrains.html) is oriented along X and Z axes, with the Y axis begin the "up" direction.
As Far As I Know, you can't rotate or change axes of neither of those.
This means that you can't ever use these together in a game.
Is there any way to work this around? For example, it would be great if you could make the 2D Physics Engine work on other axes - X, Z in this case.
↧
↧
How to calculate angular velocity after a collision?
Hi all!
I'm developing a Peggle-style game and I need to calculate the angular velocity to apply to a ball as a result of bouncing off a wall. My ball has a Rigidbody2D and a CircleCollider2D attached to it, but at some point I need to simulate the trajectory so I set it to kinematic and disable the collider to move it around and resolve the collisions myself using CircleCast2D.
I managed to implement the formulas to resolve the collision and get the resulting linear velocity and position, but I'm still struggling to calculate the angular velocity. I found some formulas and tried them all, but the results I'm getting are nothing close to what Unity sets to the rigidbody if I let the physics engine do its own thing. I followed [this][1] approach, implementing formula number 7 with no luck at all. Values are not even linearly dependent, so I assume it is not a matter of units of measurement.
My setup is as follows:
- A ball with a radius of 0,192 and no physics material in its CircleCollider2D with a Rigidbody2D attached to it (mass = 1, linearDrag = 0, angularDrag = 0, gravityScale = 1).
- A kinematic wall with a physics material (friction = 0.1, bounciness = 0.6).
- Incoming velocity for the collision: (-11,01391, -6,336001).
- Incoming angular velocity of the ball: 0 degress/sec. (it is not rotating at all)
- Collision normal: (1, 0).
- Vector.Angle(normal, incomingVelocity) = 150,0894.
Using this setup, if the ball is moved by the physics engine the resulting Rigidbody.AngularVelocity will be -1323,647 degress/sec. However, my calculations give me a value of 44,78571, that when converted to degrees/sec (the output of the formula is supposed to be in radians/sec) gives a total of 2566,032165.
As you can see, the values are not even close to Unity's output. What am I missing here?
Thanks for your time ;)
[1]: http://www2.physics.umd.edu/~mfuhrer/course/spr02/AJP/AJP00482.pdf
↧
How do I create 2D swirling wind patterns? (Use fluid dynamics?)
Hi guys,
We're making a 2D game and I want to test some 2D wind patterns which will swirl in different directions (so, not a simple horizontal directional windzone, but involving curves).
A good visualization for it is this Van Gogh painting:
![alt text][1]
[1]: /storage/temp/66532-1280px-van-gogh-starry-night-google-art-project.jpg
... Imagine a player surfing along these wind currents in the air. The wind current should therefor be able to effect GameObjects physics (the player).
So, I'm not sure how to achieve this. I've been looking at fluid dynamics with directional force applied, but I'm not sure if that's going to allow the same 'feel' as wind. I've also looked at adding force along a spline bezier curve, but I'm not sure this makes sense.
How would you guys go about this? What should I research in order to get something like this working?
Also, it would be ideal if I could randomize these wind currents, but I realize that may be just complication things.
Thanks for reading!
↧
Physics.OverlapSphere not working
if (isactive == true)
{
ParticleManager.instance.PlayPlarticles(1, 0.2f, Color.yellow, 1f, transform.position);
explodetime--;
if (explodetime == 0)
{
Collider[] hitColliders = Physics.OverlapSphere(transform.position, exploderadius);
for (int i = 0; i < hitColliders.Length; i++)
{
Debug.Log(hitColliders[i].name);
hitColliders[i].SendMessage("Damage", 10);
}
Destroy(gameObject);
}
}
it doesnt seem to work, no names are displayed in log and no damage is made.
↧
How to make flips, backflips like in game Backflip madness
Hello, how to create flips, backflips physics like in game Backflip Madness?
Or is there any assets ?
https://youtu.be/_wPDk-5SCVU
↧
↧
2D Snail-like movement
Hello,
I want to create a snail-like moving creature in 2D which is just made of muscles and nodes. The muscles can expand and contract and the nodes hold the muscles together.
This is how I want my creature to move:
![alt text][1]
[1]: /storage/temp/69724-snailmovement.png
I tried doing this with changing the friction of the nodes on the surface and by changing the scale of the muscles but that didn't work. How do I do this?
↧
How do you make 2D bounce physics work? (on a small scale)
=
EDIT: I have either solved or found a work around for this by scaling up the objects in question after seeing mention of something vaguely related elsewhere. But if that is the fix that leads to another question: why does scale break physics?
I'm making an extremely simplistic breakout model at the moment but the 2D physics refuse to work as I'd expect.
Objects in question at the moment:
- square 'ball' with 2D box collider
and rigid body 2D
- rectangular 'block'
with 2D box collider
Both are set to:
- 0 friction
- 1 bounciness
'Ball' is set to:
- 0 gravity
- 0 angular drag
- 0 linear drag
- 1 mass*
- freeze rotation Z
- "is kinematic" is off
*I've tried many magnitudes of difference here with changes to the applied force to match. No matter what the scale, the same speed has the exact same effects as described below.
When the game starts I add a force to the 'ball' and it travels towards the block. The collision is detected fine and I'm able to script destroying the block. The 'ball' loses all velocity on the Y axis, but continues to move using only the X axis portion of its previous velocity. On hitting the edge of a second block it again triggers the collision*, destroys that block as well, but loses all velocity on the X axis as well.
*to be clear using OnCollisionEnter2D
Oddly it seems to work perfectly fine when the initial velocity is higher, though it is not remarkably slow right now.
This same thing happened the last time I tried to use Unity's built-in physics. I tried to code the physics directly myself with 'is kinematic' (again this is now off) but would like to learn how to use Unity's system.
What am I overlooking?
↧
Prevent physics shaking
Hi people.. I'm having some problems with physics, my character keeps passing through moving floors/objects.
This (poorly) animation is what I expect:

As you can see in the animation above, the character keeps nice on the floor. Now the reality is this (not animation, used unity): 
Here we have two problems:
1. The character is moving to both sides (and jumping), shouldn happen, since the floor where he is standing is not rotating.
2. The character gets into the floor, sometimes he pass through the floor completely. If I increase the velocity of the rotation, it's almost impossible to make the character stand on the ground.
This is a prototype (thats why the sprites are sh**y). **Code - Rotator.cs** public class Rotator : MonoBehaviour { public float DegreesPerSecond = 80.0f; void Update () { transform.Rotate(new Vector3(0, 0, Time.deltaTime * DegreesPerSecond)); // The grund where the player will stand... Transform block = transform.FindChild("Block"); if (block != null) { block.localRotation = Quaternion.Euler(-transform.rotation.eulerAngles); } } } **Structure** ![alt text][1] The rotator is using Polygon Collider, but that Block child (where the player will be) is using Box Collider 2D. Tried to switch from Polygon to Box Collider and still same issues.
I think the player script is irrelevant, since I'm only moving the player to prevent him fall off the screen. I can disable the player script, the issues listed above will happen, the difference is that the character will fall off, so I don't think the player script is the problem.
I bet that this will happen on every moving object/ground, so, there's a way to fix this? PS. Newbie on unity and game developing.
PS²: English is not my native language.
PS³: Using Unity 5.3 x64. [1]: /storage/temp/75153-structure.png
As you can see in the animation above, the character keeps nice on the floor. Now the reality is this (not animation, used unity): 
Here we have two problems:
1. The character is moving to both sides (and jumping), shouldn happen, since the floor where he is standing is not rotating.
2. The character gets into the floor, sometimes he pass through the floor completely. If I increase the velocity of the rotation, it's almost impossible to make the character stand on the ground.
This is a prototype (thats why the sprites are sh**y). **Code - Rotator.cs** public class Rotator : MonoBehaviour { public float DegreesPerSecond = 80.0f; void Update () { transform.Rotate(new Vector3(0, 0, Time.deltaTime * DegreesPerSecond)); // The grund where the player will stand... Transform block = transform.FindChild("Block"); if (block != null) { block.localRotation = Quaternion.Euler(-transform.rotation.eulerAngles); } } } **Structure** ![alt text][1] The rotator is using Polygon Collider, but that Block child (where the player will be) is using Box Collider 2D. Tried to switch from Polygon to Box Collider and still same issues.
I think the player script is irrelevant, since I'm only moving the player to prevent him fall off the screen. I can disable the player script, the issues listed above will happen, the difference is that the character will fall off, so I don't think the player script is the problem.
I bet that this will happen on every moving object/ground, so, there's a way to fix this? PS. Newbie on unity and game developing.
PS²: English is not my native language.
PS³: Using Unity 5.3 x64. [1]: /storage/temp/75153-structure.png
↧