Unity

[UNITY] Character & map collision, Arrow key access

 

 

 

 

 

 

 

 

 

Character & map collision

First of all, BoxCollider2D are required and added to both character and map tiles to make sure proper collision detection. Rigidbody2D allows us to connect the physical properties of the character and access it from the C# script.

Initialize the object before the Start() function

 

In start(), we can access to object’s multiple components using

 

Arrow key access

Since the update() is being called every frame, we should be accessing the keyboard here.

Variable horz is float between -1 to 0 (left arrow), 0 (still), 0 to 1 (right arrow).

Rigidbody2D.velocity(x_velocity, y_velocity)