Unity3d swing ball like pendulum - unity3d

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

Related

[Solved - 3D movement on X and Y with mesh colliders

I am working on an Asteroids clone in 3D with top-down camera. This setup is static and will not change (so no, I do not want to transform the project to 2D game instead).
This means that I need to limit all movement to X and Y axis. I created movement for both asteroids and player and everything worked fine. All movements are done using AddForce on respective RigidBody components.
The problem is then I start dealing with collisions. I use Mesh Collider components to get a nice and precise "touch reaction". The problem is that when collision like this occurs, the new movement vector has Z value different from 0. This is a problem as the object will start moving on Z axis.
What have I tried:
Freezing constraints on RigidBody
Manully reseting Z in Update function
The first solution (freezing constraints) did not work and neither did the second one (moreover, the second one seems quite messy)
So the question is
What would be the optimal way to force physics-based movement only to X and Y axis while using precise collision with Mesh Colliders?
are you sure you used the position restriction correctly? You can check to set the restrictions with a vector as in the documentation. https://docs.unity3d.com/ScriptReference/RigidbodyConstraints.FreezePosition.html
to see how its done. If not please share the code or a screenshot of the rigidbody restrictions you tried in the editor

Rotate wheel collider object

I wanted to rotate a wheel collider object in unity.
I duplicated my back and front wheels objects to keep the position data.
It appeared perpendicular to the wheels. I cannot rotate it using the rotation tool or via the inspector.
As mentioned in this post: it could be solved using an empty game object for the rotation.
I tried to append it onto an Empty Game Object and rotate it. It did not work.
Thanks in advance
I had the same problem. The solution is simpler than the other answer suggests:
WheelCollider objects are dependent on the orientation of a rigid body they are attached to. Assuming that your bike has a rigid body, the solution is to make sure that the X-axis orientation of the bike matches the X-axis orientation of the wheel colliders.
Based on this post:
https://forum.unity.com/threads/unity-5-wheelcollider-wrong-rotation.349596/#post-2264801
WheelColliders always point in the "forward" and "down" direction as the rigidbody they're attached to. The steerAngle value is relative to the rigidbody's forward direction.
Please bear in mind, however, that your bike's model(the visuals that display bike's frame) might have a different orientation from the object that contains the rigidbody that wheel colliders are attached to.
In my case Hierarchy looked like so:
MainScene
CarRoot
CarModel
WheelColliders
Wheel_FR
Wheel_FL
Wheel_RR
Wheel_RL
The CarRoot had a rigid body on it. When I rotated it, that would also rotate my model. Which was not good. So I had to:
Unparent the CarModel and WheelColliders(made them children of MainScene)
Rotate the CarRoot by 90 degrees on the Y-axis(to align its X-axis with that of the WheelColliders)
Make CarModel and WheelColliders children of CarRoot again.
That did it for me.
1-) Create a capsule game object,
2-) Make it like whell.
3-) Delete capsule collider and add mesh collider, then select convex.,
Now you have a collider like whell.
4-) Put your whell game object under this, and fix sizes.
5-) Delete mesh filter and mesh renderer in capsule object.
6-) Use transform.rotate(vector3.right) or left on created base object.

2 Joints 1 Object

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;

how do i get a gameobject to conform to other gameobject shapes

Im trying to make a game in Unity and I want to have a gameObject fall and match the shape of the ground underneath it.
when the game is started:
what is does:
what I would like it to do
I'm pretty decent so even a hint in the right direction would be helpful.
thanks.
One way to do it is to duplicate the ground object and replace the falling object with ta modified version of that duplicate. How you can do that is to do the following on entering a collision between the falling object and a given ground object:
Make sure this falling object hasn't already collided with this ground object, such as with a fallingObject.lastCopiedGroundObject GameObject.
Find the y of groundObject's Collider.bounds.size
Add y to groundObject.transform.position to a new Vector3 newPos
Use GameObject newFalling = Object.Instantiate(groundObject, newPos, groundObject.rotation, fallingObject.parent).
Copy rotationalVelocity and velocity from the fallingObject's rigidbody over to newFalling's rigidbody, if appropriate.
Add, remove, modify components as necessary on newFalling, (such as replacing textures) to make it further behave and appear correctly as the falling object it is replacing.
Destroy the old falling object with fallingObject.Destroy()
Set the lastCopiedGroundObject of newFalling so that newFalling won't do this interaction with the same groundObject again, until another copy is done.
This will place the falling object above the ground object, and will let it fall using the physics engine to determine where it should rest on top.
One consideration is to instead use a List<GameObject> alreadyCopiedGroundObjects and to append the newly collided ground object to the list in the old falling object so that if the falling object touches multiple grounds, it will only change its shape to each one only once, so it won't perpetually oscillate between shapes in certain conditions.

How to get Direction after cueBall collide with any ball in unity3d?

I am creating one pool table unity game. I want to get the direction of ball to show user where the ball will move. Consider the following image for an example.
Here A is our cueBall and B is ball on the table. Let's consider that when user hit ball A in the direction as per "DIR 1" it will hit to ball B at that time ball A will be at the position of C as per image.
Now I want to know there point
How to find position of c.
What is the touch point of B & C means which place A will collide with B.
In which direction ball B will move after collide by A.
I hope this Question is clear to all and provide proper detail for my problem.
Assuming you are using a Rigidbody on your balls, you could use :
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.SweepTest.html
you will use your 'DIR1' as the parameter of the SweepTest function.
Once it returned a 'true' and confirmed a collision, you could use the RaycastHit.distance and 'DIR1' to calculate position 'C'
With position 'C', RaycastHit.point(impact position), and position 'B', you could now calculate 'DIR2'.
--
Physics.Capsule cast is also another option > http://docs.unity3d.com/Documentation/ScriptReference/Physics.CapsuleCast.html