Question 1 Unity
Question 1 Unity
Question 1: Explain what six methods are used for collision detections
in unity3D, make use of all six of these methods with an example
scenario.
Ans:
Through unity modes of collision detection:
1. Discrete Detection Mode
2. Continuous Detection Mode
3. Continuous Dynamic Mode
Detection can be done through
1. Mesh Collider
2. A Game Object with a rigid body component
3. Through Scripting:
i. OnCollisionEnter(Collision other)
ii. OnCollisionStay(Collision other)
iii. OnCollisionExit(Collision other)
with trigger
iv. OnTriggerEnter(Collision other)
v. OnTriggerStay(Collision other)
vi. OnTriggerExit(Collision other)
Example : Take a base platform making it move back and forth like a
rocking chair and use couple of balls (game objects) falling on the
platform in this way we can use all the of the above methods to
perform collision detection the balls will be knocked off the platform.
Question 2: Use Transform.Translate() in an example scenario. Also,
how give an example of a situation where you will need to make a
gameobject a child of
another.
Ans:
i. Vector3 is an object type
ii. Transform is an object type as well
iii. Translate is a method for transform object type which takes
vector3 as a parameter
iv. Vector3 has its dimension which is x,y,z so it should be given
some values.
Example: Transform.Translate(0,0,1)
Or
Transform.Translate(new Vector3.forward)
So, basically it is use to move a game object or set position of a game
object.
Transform has Position, Rotation and Scale and all have their own
axis.
Part 1:
Example: Lets have a Square our game object if we are going to
move it backward on x-axis we make our co-ordinate (-2, 0, 0) this
will make it go back a little this is for position only.
So, For Rotating and Scale we can use the different values.
But the Coordinate System is different for World Space/Global and
Self Space/local space by default it is on the world space there is
toggle button in unity which change it to local space by doing that it
will change the direction of the movement of the gameobject that
x,y and z axis.
Part 2:
You will need to make a gameobject a child of
Another:
Ans: obj1.transform.parent = obj2.transform
obj1 is the child of obj2 now