Posts

Transform.LocalEulerAngle, how to measure speed of rotational body- Unity 3D

You have to know the difference when you switch the languages !  When you start writing to code for your game you either start with the C# or java-script or any other available language. I would like to share a small difference between these two languages syntax when you  are required or like to deal with both languages. I like to code in C# but some how have to deal with java-script. Where is found some thing about a scripting API Transform.LocalEulerAngle. First lets see what these API do. Lets discuss some other Api too. Transform.LocalEulerAngle : When you have to rotate something you use this api it rotate an object around an axis.  When you write this in Javascript. Then transform.LocalEulerAngle.y= 10f. But you can n't write the same for C#. As it's a vector3 in C#. Whereas Vector3 is a struct, whereas Eulerangle will return a copy. By assigning the value 10 means that you are making a temporary change in the copy. That does not happen.  So in C# you can write

A Healthy Solution to Pivot Problem - Unity 3D

Image
I will today share a solution that i found more convenient and functional about Pivot ! So lets do it.  When we talk about 3D model ! Every character or an object have a pivot point.  That is very important that pivot should be in the center of that object. If it's not in the center we have to face many problem regarding this. Keeping the model aside. If you have imported a model in unity you have to work with it independent of the graphics and designs. If your logic is dependent on models then you have to face many problems.  Lets come across with a common problem that we face in unity is pivot problem. Models that we import sometimes have pivot disturbed position. And it's difficult to work with! Now if we have to rotate an object  it will rotate around the pivot. The object will change not only its current axis but also position. Now that frustrating why the object changes it's position. It's satisfactory if there is nothing to do in the game scene ! because w

Input.Getaxis, OnMouseDown, GetComponent< > - Unity Scripts

Image
In This Blog We Will Discuss Some more Keywords. Input.GetAxis : In this picture a chunk of code is placed. You will see that Input.GetAxis("Vertical") returns a value. The value is from 1 to -1. When there is no key pressed the value is zero. Actually it returns the value of virtual axis. If we use Debug.log then the console will show some value on clicking the right or left button that will be constantly changing.  Other thing is that Vertical is pointing towards the built in inputs. As you can see in the picture above that the vertical have some columns in it. Where the vertical have positive and negative button which give positive or negative float value on event pressed. Whereas if we don't want to use these inputs . We can write code instead of writing Vertical or horizontal in the brackets of input.getaxis. We can write it as Input.GetAxis(keycode.space); .  Here the space key is assigined and it will return some value. OnMouseDown() : OnMouse

Look at , lerp , Destroy gameObject - Unity

Image
Look at   Lets just discuss about the code and look at use. I have used the look at function to change the direction of the camera while the game is playing. As i have created a character. Which falls on the ground. Now In order to show the ball falling look at function is used that shows while playing. Now here the script is added where in the target section i have added a moving cube. That the camera demands the object on which it have to focus. Now lets see the code that simple to understand.  Now here the Transform object reference is given which demands a particular object. That is given be given in the picture above shown.  Lerp  Vector 3.lerp is used to change the position of an object between two points. In this section i have added the lerp attribute to the camera. So the camera will move between two points. Lets see the code things will get more clear. Here on the first line a Vector3 is declared. Where in the awake transform position will assign th

How to move an object in Unity 3D

Image
How to move an Object Backward and Forward in Unity 3D !  First of all lets discuss some of the key words that are necessary to understand.  Vector 3: Its a representation of 3 vector points. You have listened the x ,y and z axis. So here vector 3 takes all the 3 values. The points in the back and forward will be (0,0,-1), (0,0,1) respectively. Time.deltatime:  Function is used to make the game rate independent. If you multiply the variable with time.delta time it means you are saying that i want to move the object 10 meter per second. Basically you use delta time to update your movements. Transform.translate:   Transform.translate is basically used for the movement of the object as it takes the 3 axis value to move the object.  It's related to the distance the object will move. Now lets see some practical example to make a object working. We take a cube for the example purpose. Then add script to it. Now lets see the played situation. As my object is mo

Vector Math - Unity

Image
Vector Math  Addition:  As you that the vector addition is defined by the combined effect of two or more than two vectors. When the tail of one vector is added to the head of other vector addition is made. This can be defined by a parallelogram.Actually joining two vectors result into a new vector. Subtraction:  Vector subtraction is performed to get the direction and distance from one object to another. The addition and subtraction of vectors is similar as the subtraction of vector will have negative negative magnitude that means opposite in direction. As in subtraction head to tail rule is also used. Dot Product : The multiplication of two vectors will result in a scalar quantity. Where Theta is the angle is multiplication of the two vectors is 0 than its perpendicular. In unity we use Mathf.Cos. Which perform equal-ant function. Cross Product: The result is perpendicular to the two vectors. The "Left hand rule" can be used to remember the d

GameObject - Unity

Image
  Game Object  Game object in unity is basically a container that requires properties to make them a character. Suppose a room the type of things you will place will be the type and use of the room. Likewise, components added to the game object will define the type of the game object. Game objects have transform component attached to it that can't be removed. GameObject.renderer  Game object renderer  is use to make character appear on the screen. It can also be used to change the color of the object. Having further different properties. To change the color of the Object  Taking a small example to learn, take a cube in the scene and add a script in the cube through add component. Then add the code given below. void Update () { if(Input.GetKeyDown(KeyCode.R)) { gameObject.renderer.material.color=Color.red; } } To make Object Transparent  GameObject g; g.renderer.material.color.a = 0.5f; g.renderer.material.color.a = 1.0f; To make an Object visib