Hey I'm trying to figure out how I can achieve this effect where
left ball lowers/raises the end of the rectanggle.
and the right ball does the same on the other side.
Here's what it would look like
https://gyazo.com/7d17da64ece3e89c7ac375446c547d1d
I've been messing around this for quite a while but I can't get stable resulsts and I am confused on which hinge would be the best for this use case.
I'd imagine hinge joints but they tend to go crazy and spazz out
I need ball A to raise lower the rectangle over a pivot point above ball B
and vice versa.
There are many ways to achieve this:
1. Group both objects under the same parent and raise the parent instead of individual childs
2.Attach script to the second object that will update its position based on the first object or vice versa
Gameobject objA = GameObject.Find("ObjectA");
transform.position = objA.transform.position;
Related
Hi I'm just new to unity2d, so I have a gameObject that has an hinge joint attached to another gameObject with rigidbody, Im trying to make a Wooden board that will behave like a "seesaw" and return back to its current position when the character is not set foot on it. How can I make it behave like a seesaw thanks!
This is the Original position of the gameObject where the other end of the wood is inclined down.
This should what must happen when my character puts weigh on the opposite end help please.
I recommend in this case to use the "Motor" behaviour of joints:
https://docs.unity3d.com/ScriptReference/HingeJoint-motor.html
So if you set to the "motor" of the joint a little bit of force, it will come back to the start position.
One more recomendation, depending of the force, the joint can "bounce" so I suggest to make some script that sets the motor force only when has interacted with the player, or stop doing the force if it's already on the start position, it's up to you! :D
I am making a chemistry game in Unity where each atom is represented as a 3D GameObject sphere. I want the user to be able to drag an atom around and if it enters some set radius of another item that it can combine with, the two atoms "stick" together (or become "suctioned" together) and become one entity that can be dragged around and interacted with.
How it looks now:
How I want it to look after interaction:
Now comes the hard part trying to figure out how to do this. First, I attached a script to the Oxygen atom (red sphere). I want to see if the Hydrogen atom entered some radius. If it does, I create a new GameObject, make both the oxygen and hydrogen children of that object, give the new GameObject a rigidbody and collider, and turn off the rigidbodies of the children. So the problem with this is that once I do that, both spheres fall through the ground. Also, they still remain as separate spheres and don't look "stuck" together. If I drag the red sphere around, the white doesn't follow and vice versa.
Any help would be greatly appreciated.
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "HydrogenPrefab(Clone)")
{
Debug.Log("Hydrogen entered");
GameObject HOCombo = new GameObject();
//put both atoms under the same parent
collision.gameObject.transform.parent = HOCombo.transform;
this.transform.parent = HOCombo.transform;
//remove the rigidbodies
this.GetComponent<Rigidbody>().isKinematic = true;
collision.gameObject.GetComponent<Rigidbody>().isKinematic = true;
// make the parent a rigidbody;
HOCombo.AddComponent<Rigidbody>();
HOCombo.AddComponent<MeshCollider>();
}
}
It looks like a Fixed Joint could suits you.
Also make sure that you get the right object when you Raycast it. You'll probably need to move the children to a layer ignored by your raycast or use RaycastAll to get all hits (not just the first one) and manage to find the desired parent from there.
so basically i have a target like the type for archery the 3 rings (bullseye, inner circle and outer circle)
now i basically used a cylinder to create these and then added to them rigidbody2D and a circleCollider 2D , now my problem is because the rings are essentially on top of each other i have them layered out on the z axis a little to make them all visible but when it comes to doing a raycast2d on the target it isnt picking correct ones up for example it goes from outer circle straight to bullseye and skips out inner circle yet all have colliders set up the same way
i cant figure out a way to overcome this and if not ill have to change to a different target where nothing overlaps in order to get it to work but i would really like the archery type targets
Thanks
You could just vary the distance from the camera for each ring so that the ones over the top are hit first.
Alternatively you could add tags to the three rings, use raycast all, and check the tags of all hit colliders to decide which one was hit first. For example, if all 3 register a hit, then you know the center was hit, and if the outer 2 register then you know it's the inner ring, and so on.
http://docs.unity3d.com/ScriptReference/Physics.RaycastAll.html
Hello every unity programmers and stackoverflow members. I'm progressing past article's project
I have no solution before article. So I changed to other method.
I want a animation like pendulum moves. I make 2 object A and B;
A: Added rigidbody component setted with IsKinematic.
B: Add rigidbody component setted default; and add Hinge Joint and set connected body to Object A. and have suitable offset with A.
And when I play this, it(Obj B) has no action. To give movement I move B object in Scene mode, But B goes it's position.
Why? How Can I Solve this Problem. I want animate the Ball B like pendulum.
add the hinge joint to object A not B (with isKinematic set to true) and set the axis you want
attach object B to the joint
I need to animate an object along a path. I am doing so by creating an animation like:.
This works great but since my terrain is not flat it will be nice if I don't have to deal with the y component. In other words I want to move an object along the x-axis and z-axis and if there is a small slope increase then increase the object y position. same thing if there is a downward slope. Or maybe I have to create a script where it checks to see if the object is colliding with the terrain. if not then decrease its y position. I don't know if this will work meanwhile animating an object though.
I think the easiest way I can think of to solve this is for you to make the object a rigid body and use collision (probably a mesh or capsule collider if its a player character) to get it to sit on the floor.