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.
Related
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).
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
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.
I'm creating a Super Mario Bros. remake for the iPhone using Cocos2d.
I'm having a hard time understanding how add real objects to a tiled map.
I know that you can add an object-layer to the tiled map and set the position of it,
but I'm not sure how to define WHAT object if should be.
For example, I'm creating a simple Super Mario Bros.
I want to add different blocks to the map, one should hold a star, one should hold a coin, and so on.
So my question, how do I correctly create class-objects in a tiled map?
I have used object layers in the past. For you needs you could create an object layer and drop an object on that layer. Type of box. It could have variables in the object of powerup then the value could be whatever you want. Coin, 1Up, Star etc..!
I have 3 OpenGL objects which are shown at the same time. If the user touches any one of them, then that particular OpenGL object alone should display in screen.
Just use gluUnProject to convert your touch point to a point on your near clipping plane and a point on your far clipping plane. Use the ray between those two points in a ray-triangle intersection algorithm. Figure out which triangle was closest, and whatever object that triangle is part of is your object. Another approach is to give each object a unique ID color. Then, whenever the user touches the screen, render using your unique ID colors with no lighting, but don't present the render buffer. Now you can just check the color of the pixel where the user touched and compare it against your list of object color ID's. Quick and easy, and it supports up to 16,581,375 unique objects.
You would have to parse every object of your scene and check the possible collision of each one of them with the ray you computed thanks to gluUnProject.
Depending on whether you want to select a face or an object, you could test the collision of the ray with bounding volumes (e.g. bounding box) of your objects for efficiency purposes.