How to update the angle of objects - sprite-kit

I want to update angle an object is pointing so that it is always pointing in the direction of travel. I assume that I would put the code to do so in the update method
- (void)update:(NSTimeInterval)currentTime
How do I find all the objects of a certain category in the scene, I guess I can iterate over all the scene objects but is there a more efficient way to do this perhaps by enumerating over certain categories of objects?
Update:
Another option might be to attach an SKAction to each object. Is it possible to create a custom action that will be able to use the nodes velocity to change the rotation ? If so can someone provide sample code. Thanks

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).

Can multiple game objects share properties? For example, a single quaternion that multiple objects use as their rotation value

Can multiple game objects share properties? For example, a single quaternion that multiple objects use as their rotation value. I basically want to have every objects's transform.rotation be a pointer to one quaternion so I can rotate them all without updating every object.
No they can't share the properties but you could make a singleton so you only process the data once and assigns it in the update from the others scripts/objects.
If I were you I would create a Singleton with the modifications to the Quaterion,and with a public access to the Quaterion, you could access from any script.
So in that way in your update you will have just to set the rotation to the singleton value.
If you need more help let me know.

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.

Unity3d Transform issues when trying to re-parent a Gameobject with sub-Gameobjects

I am trying to grab a Gameobject that's placed in the correct spot and re-parent it to different Gameobject transforms using code. I manage to do this by using ..transform.parent = parent.transform but the rotation and position get messed up. How can I keep it's rotation and position when re-parenting?
Thanks!
Always use gameObject.transform.SetParent(anotherGameObject), or you risk exactly the sort of phenomena you've described. See SetParent docs; there is a second parameter to consider.
The form mentioned in the question still works in many cases, but has been deprecated for a while.
Place all game object that you want to parent, to empty game object(example:"EMPTY\PARENT\EMPTY\CHILD") with scale 1:1:1(in editor)or re-scale your parent game object to 1:1:1

Drag and match objects

I want to make a game which needs to drag an object (UIView class object) and intersect with an another object (UIButton) and the same time an event generates , and checks the matching of object is right or wrong.
If wrong the objects come back to its position.
The touch and drag I have done with the object but elasticity of the objects position is not working properly ? Any example or help Please
If you're using standard (non-GL) programming, you can use the object's frame to check if the objects intersect. There's a call for it. You can take the relevant points of one object and check if they are inside the other object's polygon. If they are, then you have a collision. The Quartz 2D drawing tools have lots of intersection methods for these types of objects.