I assume this is pretty easy but I did not find a solution yet. I have a 3D environment for VR in Unity. I have a Canvas in Worldspace which you can grab and move around like a tablet. In order to be able to touch the buttons on the canvas, I added a sphere on the tip of the controller's finger as a detector with a sphere collider. To the buttons on the canvas I added rigidboys and a boxcollider. With a onCollisionEnter Event I handle if the button and the finger are colliding and execute the onclick.Invoke() function.
It is working, the problem is if I touch the buttons they start moving and float around in the environment. If I freeze their position they won't be moved if I drag the whole menu around. How could I solve this?
Using Unity 2019.4.19f1 with Oculus OVR Plugin.
Ok, I solved it with the idea of setting them to kinematic as JustARandomWibuuuu suggested. If someone might have the same problem.
I've set both to kinematic and in Project Settings → Physics → Contacts Pair Mode I had to enable all contacts.
You added rigidbody, so it will be a physical button, it will be affected by gravity, force, drag, ...., So it is floating because it is in 3D. You can use static rigidbody to do it
Just click true on
Rigidbody.isKineMatic
Related
The title doesn't really explain much so ill expand more. I'm making a 2D game where you move a mouse to help you do stuff. I am using a fake mouse which is controlled by your mouse. And I want to make it so the mouse can't just move through walls. I've tried adding rigid bodies but the mouse still passes through it, or the wall just gets pushed by the mouse. (The mouse has a RigidBody2D script on it and a polygon collider 2D and the wall has a box collider 2D, and a RigidBody 2D) Thanks for the help.
If both have what you say, mouse has rigidbody + 2d-collider and walls have 2d-collider then it should work. A few things to note: it will only work if you move by physics (ie not teleporting each frame) and don't move it too fast (change rigidbody collision setting to "continous" if so). – Fredrik Schön
This solved it for me, Thanks
I have a sphere collider on a stick and a cylinder. The cylinder has to detect a collision with the sphere collider of the stick and fire up a "OnTriggerEnter" script. Just imagine it like a drum stick hitting a drum in virtual reality.
Is there a way to avoid registering a collision on the sides of the cylinder, but only trigger on the top of the cylinder? And even without adding more protecting objects around it?
In the screenshot you see the properties of the stick and below the properties of the cylinder.
Obviously the green and red icons show which area is allowed to be triggered and which not.
Btw, simply using a thinner cylinder collider doesn't work in this case, because it wouldn't detect some collisions at all, when the stick goes too fast trough the thin cylinder. More about that in the comments.
Thank you.
I am working on a 3D unity project, which I have a platform in it and a character who runs on that platform, I placed the character on the platform but it started to fall down so I solved the problems by following these steps:
added a capsule collider to the object, it still fall through the platform
added a collider to the platform, then it didn't fall down but now these two objects are soled to each other so the character is just moving her legs in the same place,
Is there any way to make the character move on the platform while still using colliders?
Note 1: I made the collider trigger in the image to make the same exact behaviour with out colliders.
Note 2: I tried to put each one of them on a different layer but I get the same problem.
code:
void Update ()
{
rbody.velocity = new Vector3(rbody.velocity.x,0f,playerVelocity*Time.deltaTime);
rbody.transform.rotation = Quaternion.identity;
.
.
.
}
Making the collider trigger is like adding no collider. Trigger is only used when you want the collider to detect something but not stop it from running into things. So I believe you should add a non-trigger collider to both the character and the platform but make sure that the colliders are not intersecting when you put the character manually at first. If that didn't work, tell me exactly the coordinates of the character and the platform and the sizes of their colliders and I will try to replicate your scene to figure out the problem. Hope this helps!
Hi Friend you have 2 options...
Change the mass of your RigidBody
Use PhysicsMaterial and reduce the friction between the objects (Add a Physic Material to your Platform)
Increase the force and movement speed in your script.
i imported a the Unity chan character from unity assets store , when i and i added to it rigidbody and capsuleCollider ,and then i assigned to it the
JUMP00 animation as in the images , so when i hit play the character jumps but the collider is not moving up , when i add motion to move x and z axis the collider moves with the character.
This behavior is by design. Animation only move the mesh, it does nothing to collider.
One workaround to this problem is that you can attach your collider to the bone not the mesh.
I just solved my problem which has the same behavior. The cause of my problem was because I did not move the GameObject (up), I just was playing the animation, not make a really jumping for the object.
I know this old post, but I answered for the newer game programmer like me :)
As shown in the picture, I want to be able to maintain this placement of virtual buttons wherever the ball moves.
This is what I've tried:
1.
The cue ball is a Rigidbody with Bounce Material, so it can bounce off the cushions. So in this case, I tried making the Virtual Buttons RigidBody Components and adding the same force to the buttons, but this didn't work because it wasn't able to detect the cushions and kept moving forward.
2.
I gave it a collider, it would bounce off the cushion before the ball and that would disrupt the formation around the ball.
3.
I tried to parent the Virtual Buttons under the Cue Ball and the Cue Ball under the Image Target, but this didn't help since it all centered within the ball and overlapped. I couldn't move it at all (I don't know why)
Willing to put a Bounty on the answer.
Virtual Butttons sometimes don't move above the Image Target, I really don't know why. But here's a work around.
Now consider your CueBall the parent. Throw in 8 Empty GameObjects as child Objects. Position these GameObjects in the position around the ball that you wish to maintain through the movement.
Now each virtual button is put as a child to these GameObjects respectively.
And now script movement of the ball. You should see it works perfectly. Make sure you have your X and Z rotation restriction. I guess since it's a Cue ball and its white, the rotation won't be much of a problem, unless you're scripting for Curve shots as well.
Hope this helps.
A solution might be to create a script to attach to your ImageTarget, that has 9 public transforms, (your 8 planes and the cue ball) that would then look at the cue ball's x and z coords, and then would change the planes' x and z coords accordingly.