How to implement Spring joint in Unity in the following manner? - unity3d

I need help regarding the spring joint. I am trying to make a game where when I drag back and release the gameObject should fly like in Angry Birds(but slightly different). The difference is, I don’t want the gameObject connected to the spring joint to move when i drag back. But when i release, the gameObject should move as if I did drag back.

You could create a custom spring. Spring forces are proportional to the distance from the resting point. So your force would be roughly
[pseudocode]
Force = Coefficient * (PositionOfMouse-PositionOfRestingPoint).magnitude
Rigidbodyofobject.addforce(result)
So to not move the object, calculate the mouse position relative to your object (probably need to raycast to a plane during mouse drag) calculate the force as if the mouse point was your object. But don’t actually move the object. Then apply the spring force to the actual object.
You might need to add some kind of coefficient in to modify the force, which would represent the tension of the spring.
Then you'd just need a script to turn off the spring a short time after releasing it ().

Related

Get result of add impulse if object was not moved

So, lets say my character has the ability to push "movable" objects. This is alredy implemented and working as desired.
But I want to make the characher be pushed back if he tries to push an object that is hitting a wall or an immovable object, is there a way to see if my add impulse had any effect?
Or a best way to do is some ray casts on the movable object boundaries to see if is touching any other thing?
For characters you can use Launch Character. It's like adding velocity giving a specific direction. Add Impulse is intended to be used with Objects that simulate physics.
Just Launch the Character to a direction opposite the direction it's touching. You can use Dot Product between Character Velocity and the Object Face (forward).

Hololens Spatial Mapping Collision - Mixed Reality Toolkit

I want to put a hologram-poster in AR, on the Hololens 1, on a wall using the Mixed Reality Toolkit. But everytime I try to put a hologram onto the spatial mapping it slides right through it and vanishes behind the spatial mapping.
What did I miss?
My understanding is you are implementing tap-to-place that enables users to move objects and place them on real-world surfaces. And your issue is that when you placing the object, it did not place on the surface as expected.
Usually, in MRTKv2, the Solver would be a good direction to implement tap-to-place.
The SurfaceMagnetism Solver can cast rays to surfaces in the world, and align the object to that surface.
So, you can add SurfaceMagnetism Component to the object and create a script that has two methods, one that turns on the solver when the object is selected and one that turns off the solver while the object is deselected. When you close the solver, the object will stay in the last position.

LookAt while Hinge Jointed

I do not understand, why jointed object can't look at target.
Example: 2 boxes with hinge joint (anchor is at the touching place) and a target object. When I say A-box to lookAt target, I think it will just turn on X-axis. But both of the boxes start to shake. Why?
Take a moment to reflect on what a call to LookAt is trying to do.
It's rotating the transform while ignoring physics.
That's bound to create problems, since you're not rotating the whole system, you're moving one part of it. Your rotation with LookAt is "fighting" with the adjustments the physics system is trying to make.
To solve that conflict you can do one of the following:
Rotate the entire system (both cubes). This will involve putting them all under one transform, and having that transform rotate.
Use a physics-based approach. It won't be too hard, but won't be as simple as a function call. You'll probably need a simple PID controller such as the one outlined in this thread.

Unity3d - check for collision on non moving objects

I have a sphere build from multiple objects. What I want to do is when I touch/click an object, that object should find all adjunctive objects. But because none off them are moving, no collision detection can be used.
I can't find a way to detect these adjunctive objects even when the colliders do collide with each other, as I can see that in the scene. I tried all the possibilities, but none off them are working, because no objects are moving.
Is there a way to check for manual collision detection, or is there some sort of way to let Unity3d do the collision detection automatically?
You could keep a list of all those objects, then when your event happens you can send messages to all them to do what you want them to do.
Lets assume you want your sphere to break into little pieces. You send a Force message to the sphere. Then you use Newton's Laws of motion and find out how much velocity each piece gets. Remember velocity is a vector thus it has direction.
This is how I would do it and still keep the right amount of control over what happens in my game/simulation. Remember F = ma.
you could use RaycastHit (http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html) for your collision, this also works on non-moving objects but it needs more performance
You can add rigidbody to every objects; when you touch one of them, give a force onto it, then it is going to move and trigger event of the adjacent objects.
for the reason you do not want to move the object you touch, you can cancel movement in the OnCollider or OnTrigger event handler function.
I managed to work around this by checking the distance from the selected object and all other objects that are part of the sphere. If the distance is below a certain value, then it is an adjunctive object.
Although this is certaintly not fool proof, it works without problems so far.
I am sorry I was not clear enough. Thanks for all the advice what so ever.

How to make object fall in line with the target when applying wind effect?

I am making a paper toss kind of game in Unity3d. I am implementing wind effect using constant force. I wanted to know how to make object fall in line with the target ie, if the object gets over the target, it should go in or fall in line with the target, not go behind or in front of the target. At present when I swipe applying a constant force, for different angles of swipe the distance moved by the object differs. Help would be much appreciated.
In FixedUpdate, use Physics.Raycast to check to see if the object is over the target. If so, set the x and z values of rigidbody.velocity to be zero (assuming y is the up/down axis in your game world) and disable the ConstantForce component (i.e. gameObject.GetComponent<ConstantForce>().enabled = false). Note that this won't be most realistic of movements, as it will seem like the object suddenly moves straight down when it goes over the target -- but it sounds like that's what you want.