I added the Reasonance Audio Source to an object and wanted to generate a sound when a collision between that object and another object occurred.
The issue I am having is that OnCollisionEnter in Unity is triggered whenever the object gets within the "audio region" (a blue disk attached to the object with a certain radius). However, what I am interested is when the physical collision occurs, and not this "audio" collision.
One way to go around it is just to create a copy of that object, without the Reasonance Audio Source which follows the motion of the other object. Then you trigger collisions the object copy. But I was wondering if there is any way to differentiate these two types of collisions in Unity?
Here is an example. Red ball is the object I want to generate the sound from and that has the Reasonance Audio Source as a component. The blue region is created from that component. Whenever the blue disk touches the grey floor, a collision is generated. I would like to disable this "audio" collision and have only a collision being detected when a physical collision between the red ball and the grey floor occurs.
EDIT: Found the problem. I had been testing the PhysicsManager properties (Edit/Project Settings/Physics) and I had the "Default contact offset" set to 0.01 which by change was the same as the blue region, so I went looking for a problem in the wrong place. I now changed the contact offset to a smaller value and all is ok.
In the PhysicsManager properties (Edit/Project Settings/Physics) the "Default contact offset" defines the blue region. Change the value to a smaller one to resize the contact region.
OLD ANSWER:
Without knowing your scene or code i can only speculate that you might want to turn of the audio sources collision and trigger it manually when the collision with the object occurs. Just attach a script that listens for a collision and then trigger the collision event of the audio source (or just play the sound).
Related
enter image description here
please help me
I want to move my character and jump but whenever I press play my characters parts like the hand and legs etc. keeps separating I want then to be intact and move and jump .btw they are in dynamic
Use Joints to create connections between physical objects.
Each physical object ceases to depend on the hierarchy.
If you do not need physics, then you can make objects kinematic or remove physics altogether.
click here for gif show of what I want
I want to remove mesh of object when user click on object and also remove its collider to make another object fall from that removed mesh area...
I am using unity since last month so I don't have much experience and knowledge, please help me...
Creating the destructable ground particles
One way to achieve whats shown in the gif is by creating a prefab of e.g. a circle collider that is instantiated in the area of where the dirt is in your gif. It acts as a "ground particle" and keeps the objects above itself.
You instantiate a lot of them in the area so it acts as a big collider although it is actually a whole array of smaller colliders.
Implementing the interaction logic and deactivating the ground particles
Ater that you implement the functionality of dragging the mouse over the ground particles, removing them. That is also not difficult. Shoot raycasts into the screen at the postition of the mouse (remember to use Camera.ScreenToWorldPoint) and get the collision information (confer to https://docs.unity3d.com/ScriptReference/Collider2D.Raycast.html). With the collision information you can get the reference to the instance of your ground particle(raycasthit.other.gameobject) which is then disabled through script(gameobject.setActive(false)).
I am making Network game using Unity. I want to configure my network using PUN2. In particular, I notice that I can synchronize several basic variables through the OnPhotonSerializeView () method. However, this does not include custom classes such as GameObject and Transform. So what should I do to synchronize the Target Transform in that inspector view?
There are a few ways to tackle this. It depends on what you need this target for, and if it makes since for the object to exist on the other clients if it's not being targeted by any object.
Suppose you have Player that is synced, and a blue ball and a red ball in the scene.
The player has a ball that they are "holding". You want to trigger a synchronization so on all clients, if the player is holding a red ball it will hold it for all clients, and if they hold the blue ball it will do so for all clients.
The problem linking the blue ball in one client to all the blue balls in everyone else's client.
Option a) Give each ball a name and have some static dictionary mapping their name to the object in the scene (you can make them add themselves on the Awake or Start of the ball). Now you can synchronize the name of the ball that a player holds (a string in oppose to an object). When a client gets the name change, you can handle the name change as looking it up in the static dictionary, and setting it as the ball being held.
Option b) Synchronize the player AND the balls. Anything logic-related will only happen for the current player. So if the local player holds a ball, the player position will be synced and the ball position will be synced but nothing else will happen for the other players. This of course assumes this works for whatever you are trying to accomplish.
Option c) Serialize the ball. Send the data which describes the ball (size, color, etc) and create a new instance on the client side. This will NOT be tied to any existing balls on the client side. You may need check and destroy whichever ball is already being held. This is probably the least effective way to accomplish this, performance-wise.
I am using Unreal Engine to create a puzzle game. In this game, the player has to pick up a chair/table and place it on a pressure plate in another part of the room in order to unlock a door.
When play testing, picking up objects causes my character to slide back. Once the sliding starts, there is no way to make the character stop sliding. I suspect that this issue may be caused by the object's collision volume entering the character's. However, when I release the object, my character keeps gliding backwards even though by then, the object's collision volume is out of reach.
On my character's blueprint I have locked rotation on all axes, so that it won't randomly start rolling backwards after picking up an object. This solves part of the issue but there is still the gliding that just won't stop.
I am new to UE and I have no idea what may be causing this issue. If you have any previous experience in this or simply want to chime in, please do!
Another alternative fix is to lock the rotation of the collision component in the default pawn that you have or to increase angular damping.
To do so, open the default pawn blueprint and under the physics section, then constraints, lock rotation in the X, Y, and Z axis. Or increase angular damping.
Dont know why this is happening exactly unless we see the actual settings you are using and the BP but when you pick up the object , disable its physics and collision and when you put it back enable it after a delay of 0.5 or 1 second . Hope this helps.
I am working on small game and in that bonus stage is there. There are few stars(UIImageView) available dynamically created. When Player touches those stars it gets points. Player(UIImageView) can move on sensing accelerometer data from left to right and also can Jump if stars are at some height.
However I am unable to fit the logic for collision between Player and Star Image as those stars are being created dynamically at random positions how to sense intersections between Star and Player.
Should I use some timer which continuously checks for intersection between star and Player? This is not proper solution I believe as it will consume too much memory.
Please suggest me some mechanism so that I can proceed further. How to do this ?
No need for timers, just put your collision detection in the same place where you are handling player movement.(i.e., after you have moved player's UIImageView, test to see if it is touching any star)
(BTW, you should keep an array with references to the available stars to be able to test them for collisions)