Jiggling a gameobject in Unity - c#

How do I make a gameobject like a sphere to jiggle in space, meaning rapidly moving around in random directions while holding it's original position.
I know I can come up with some really long codes to kind of simulate this but I was wondering if there is a trick to it.
Thanks

I think what you want are joints. You can attach a spring joint component to a gameObject with a rigidbody. On the spring joint, set the connected body to a seperate gameObject with a kinematic rigidbody, then play with the spring joint settings until you get a nice jiggle effect. Probably increase the Spring value a bunch.

Related

Is there a way to make clickable/interactable particles in Unity?

I want to create a bubble-pop mechanic where bubbles will fall from the top of the screen, and the player will be able to 'pop' them by clicking/tapping on them.
Basically this: https://www.youtube.com/watch?v=OH4dcpSk7n0
I started by creating a particle system. But is there a way to attach a script to the particle? Or should I go about it in a completely different way?
you should not use particles to achieve this, instead you should make a GameObject with rigidBody and collider attached to it, and spawn those GameObjects in the position you want.

How to make an object not able to pass through an object? Unity

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

Restrict Player Movement to a Area of the Map Temporarily Unity Game Development C#

When my player gameObject collides with another gameObject, I want to keep the player from leaving a small area around this other gameObject until the player has defeated the enemy. In other words restrict the movement of the play until the enemy has been dealt with. I just don't know how to restrict the movement temporarily to a small amount of space local to where the initial collision took place.
I think possible solutions are to clamp the transform, or to create a another gameObject to physically keep the player in this area using rigidbody and a collider.
My player controlled movement right now is simply Input.GetAxis for both vertical and horizontal input and using transform.translate.
Thanks for reading my question. Any help would be appreciated, even something you might think is obvious, I'm still new to this. Thanks a lot.
Without knowing any details about your game (2D,3D,etc.) my initial thought for doing something like this would be to spawn invisible wall gameObjects around your player and the enemy they collided with. Action games like Devil May Cry do this a lot, except they have pre-defined level spots where the walls are going to spawn.
When the player defeats the enemy, you could delete the walls.

How to detect collisions for a rotating child object in Unity3D C#?

I am making a First Person Shooter and I have a rigged player with a mouse look script, and I used to rotate the spine with spine.transform.rotation, but this method does not look for collisions, this means if I rotate and I am standing near to a GameObject, I glitch/bug through the object. So I tried to do it with a Rigidbody but this doesn't seem to work, I tried: rbSpine.AddTorque(new Vector3(mouseLook.y,0,0), ForceMode.Force);. This doesn't do anything. And I have another problem with the Rigidbody, I've only a rigidbody attached to the spine, my player has multiple simple collision and these overlap eachother a little, and my rigidbody is pushed away into the air slowly. Does anyone know a solution for this?
I put a rigidbody component on the player, this will take care of the collision detection for itself and all its child objects.

Unity3D Object 'Shoving' Mechanic

I'm trying to make a 2D top-down perspective game in which I want to try and implement a shoving mechanic as a way of the player interacting with the environment or even enemies, but I can't seem to nail down the physics behind it.
(Player object (P) and interactive object (O))
My Question is: what is necessary to make this work properly? I've tried a few things out, such as having the information to add the force to the Rigidbody2D on P first and then on O and I'm trying to get it so that the player pushes the object in the direction it's facing, which I have a script for transform.up to face the mouse. I did also try to implement a dash mechanic to see if it would push an object further, however the physics meant that P would dash in a random direction as opposed to being towards the mouse
give the player object a rigidbody and a colider and the object a colider, should work no problem then!
http://docs.unity3d.com/Manual/class-Rigidbody2D.html
http://docs.unity3d.com/Manual/class-BoxCollider2D.html
should just work automatically then, Unity doing all the physics work for you
edit
if you want the object to be more strongly affected just reduce it's mass int he rigidbody in the inspector, or increase the players mass

Categories