Backstory

A few of my stories actually have some history to them. For example, ‘Beams’ comes from my own childhood, where I thought fairies lived in the streetlights and guided us home at night. Of course, I’m…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Getting started with Unity3d

There is a lot of things that you can do with Unity and take my word for it, it’s quite overwhelming. Since I started learning about Unity for the evolution of Reinforcement Learning, I have realized, as long as I take small steps forward, it will all fall right where I want it. So here I am writing about creating and controlling the Game Object, and hope it will be helpful for others as well.

Go to the hierarchy menu and create a plane from the ‘3D Object’

Create the game object Sphere

Create a sphere with the ‘Create’ option under the ‘Hierarchy’ menu. Don’t forget to change the transform values to (0, 0.5, 0) so that it sits on the plane that we created above.

Add the material component to the sphere as per your requirements.

Add a Rigid Body component to the sphere. All that’s left is to define the controller of the sphere.

Add control script to the Game Object

One can add the script in the sphere as a component or write the script separately and then connect it to the sphere, it doesn’t matter how you do it as long you are proceeding in the right direction.

The script that binds the movements of the gameObject with the keyboard strokes needs to be written in C Sharp, and as follows:

Class ‘roller’ is inherited from class ‘MonoBehaviour’ and written in the script named ‘roller.cs’. Since all the necessary methods and variables will be inherited from the parent class, what we need to focus on are just the methods mention above. The above code only handles the force added to the object but doesn’t deal with the sphere falling off of the platform.

FixedUpdate() is the function which will update or act upon the game object after all the physics calculations, whereas start() is to initiate the rigid body component on the game object on which the force is applied.moveHorizontal and moveVertical are arrow key inputs taken from the Input class methods. Since there is public variable ‘speed’ of type float, one can edit its value on the run, make sure to change it to some positive value before running the simulation, as the default value is 0.

In the end, you have a keyboard controlled sphere on the wasteland. I hope whoever is reading will get something productive from this article. Til the next time…

Add a comment

Related posts:

ZL plunges into Dark Ages as Zwain calls for reform

It was a tale of two faces for the Reds when their first win of the season was tainted by controversy on an icy December evening. Reds produced some of the finest attacking football seen this season…

WNBA Weekly Power Rankings

Her Hoop Stats WNBA Power Rankings for the Week of July 15, 2019

A Frog Called Freddo

Our little green mate We met on a dinner plate Not headed for our tummies Instead we became rather chummy A love of music we share Yourself a croaking extraordinaire You used our van as a place to…