Control Character Movement from RectTileMap

# Course Introduction

You control the character's movement with KinematicbodyComponent in RectTileMap. A creator can make the character move and jump freely on the 2D plane through KinematicbodyComponent. The creator can also draw shadows. Today let's learn about KinematicbodyComponent and look at use methods with simple examples.

##### API Reference

[KinematicbodyComponent](/apiReference/Components/KinematicbodyComponent)

> Learn More Reference [Using RectTileMap](/docs?postId=589) for details on RectTileMap.

# KinematicbodyComponent Introduction

Let's take a look at the properties of KinematicbodyComponent in the Workspace - DefaultPlayer - Property window.

[{"Property":"Acceleration","Description":"This feature is deprecated. Please use SpeedFactor."},{"Property":"ApplyClimbableRotation","Description":"If it is True, the character on the rotating or slanted ladder will be affected by the shape of the ladder. If it is False, the character is not affected by the slant or rotation of the ladder."},{"Property":"EnableJump","Description":"If it is True, it uses the jump feature."},{"Property":"EnableShadow","Description":"If it is True, it uses shadow."},{"Property":"ShadowColor","Description":"The shadow color."},{"Property":"ShadowOffset","Description":"The shadow's position."},{"Property":"ShadowSize","Description":"The shadow's size."},{"Property":"ShadowScalingRatio","Description":"The rate of change of the shadow's size. The size varies depending on how high the Entity jumps."},{"Property":"EnableTileCollision","Description":"If it is True, it will collide with a square tile map."},{"Property":"JumpDrag","Description":"Controls the rate of the jump speed. The greater the value, the faster the fall."},{"Property":"JumpSpeed","Description":"It controls the speed of bouncing up when jumping. The greater the value, the higher the bounce."},{"Property":"SpeedFactor","Description":"When moving, this value is multiplied to the speed traveled in the X or Y direction. The greater the value, the faster the movement."},{"Property":"Enable","Description":"If it is True, it enables KinematicbodyComponent."}]

# KinematicbodyComponent Use

## Create Speed Increase Tile

Let's create a tile to increase speed when stepping on it.   


  1. Set the tile map mode as RectTile. [png](16582959899857d48535b46064d39a8b24d45268f5e02)   

  2. Press the [+] button on the upper left of the Tile Set Palette, then select Create TileSet From Template - BnB Tile Set. [png](169034747395370bf20b37bcd4b86900f6f1b9c52284f)   

  3. Set the name of the Tile Set as BnB TileSet. [png](1690347500526ff0abc6e49f34688b95fbe284a378453)   

  4. Click the Edit button on the upper right of the Tile Set Palette to change to Tile Property Edit mode. [png](1658300856970ff2537ee3b9f46a7a74b1756bf4d48cb)   

  5. Check if it is movable from the editing target, then select a tile without making the character move. The green arrow icon refers to a movable tile, and the red arrow icon refers to an immovable tile. [gif](1658368512967a68f8090145147d99c7dccea02d22577) It removes the edition mode after editing.   

  6. Select Layer1 from Map Layer and then create a map. [png](16582986986052598c60d8a5c4f97bd12a101ee3feaba)   

  7. Create Layer2 by pressing the  button in Map Layer, then decorate the map by placing houses and trees. [png](16582993425778cfc274e817a4e18876539fddcf14ec2)   

  8. Press the  button in Map Layer and add Layer3. [png](16589727962500e6f27c08a514189afcd6c49e7ad6047)   

  9. Press the [+] button on the upper left of the Tile Set Palette, then select Create Empty TileSet. Add a new Tile Set with the name Buff TileSet.   

  10. Press the  button on the bottom left of the Tile Set Palette, then select Add ResourceStorage Image. [png](1690349260069399d7e9a5a21497d9c52ec63ab26c4c2)   

  11. Click the Sprite that has been searched with the RUID below from Resource Picker - MSW Resource to add it to the Tile Set. Buff: 02652c247d9d40518702255bed1376c8 Trap: 510cf1b467634a3db7624041432c3de5 [png](16810900445520aec35be4e2f446ba329e093a22f61ba) [png](168109006571334c6e0622b7347388c4fc77829c32f55)   

  12. Switch to Tile Property Editing mode, then double-click the names to set them as Buff and Trap for each. [gif](1658369458607f8a560fe2565473b85ae6823a370224f) It removes the edition mode after editing.   

  13. Place the Buff tiles on the map while selecting Layer3 from the Map Layer.   

  14. Under MyDesk, create a new script component CheckSpeedBuffTile and add it to DefaultPlayer.   

  15. Write CheckSpeedBuffTile as below. 
         
         @Component
         script SpeedBuffTile extends Component
         @ExecSpace("ServerOnly")
         method void IncreaseSpeedFactor()
         local kb = self.Entity.KinematicbodyComponent
         local oldSpeedFactor = kb.SpeedFactor
         local newSpeedFactor = Vector2(oldSpeedFactor.x + 1, oldSpeedFactor.y + 1)
         
         kb.SpeedFactor = newSpeedFactor
         end
         
         @EventSender("Self")
         handler HandleRectTileEnterEvent(RectTileEnterEvent event)
         -- Parameters
         local Kinematicbody = event.Kinematicbody
         local TileInfo = event.TileInfo
         local TileMap = event.TileMap
         local TilePosition = event.TilePosition
         --------------------------------------------------------  
         
         -- When the Buff tile is stepped on, SpeedFactor is increased.
         if TileInfo.Name == "Buff" and Kinematicbody:IsOnGround() then
             self:IncreaseSpeedFactor()
         end
         end
         end
         



    
    
             
    
    16.  Let's watch the speed increase when you press the **[Play]**  button and step on the Buff tile.
        [gif](165830449805569dd931c42f04da08e73ac13afcbf882)
    
    ## Avoid Obstacle Tile
    
    Let's create obstacles that a character must jump over and set the character to die if they step on the obstacle.
    
    1. Place Trap tiles on the map.
          
    
    2. Under **MyDesk**, create a new script component **CheckTrapTile** and add it to **DefaultPlayer**.
          
    
    3. Write the **CheckTrapTile** as below.
    
        ```lua
    @Component
    script GroundTileHazardDetector extends Component
        property string CurrentTileName = ""
    
        @ExecSpace("ClientOnly")
        method void OnUpdate(number delta)
        local kb = self.Entity.KinematicbodyComponent
    
        -- It collides with tiles only when on the ground.
        kb.EnableTileCollision = kb:IsOnGround()
    
        -- The character dies when stepping on the Trap tile. Jump carefully!
        if self.CurrentTileName == "Trap" and kb:IsOnGround() then
            self.Entity.PlayerComponent:ProcessDead()
        end
        end
    
        @EventSender("Self")
        handler HandleRectTileEnterEvent(RectTileEnterEvent event)
        -- Parameters
        local Kinematicbody = event.Kinematicbody
        local TileInfo = event.TileInfo
        local TileMap = event.TileMap
        local TilePosition = event.TilePosition
        --------------------------------------------------------
    
        self.CurrentTileName = TileInfo.Name
        end
    end
    
    
    
      
    
    

  4.  Let's see if the character can jump over the Trap by pressing the [Play]  button and die when stepping on the Trap by mistake. [gif](16583053608016b9cb5709e7749bcb2a121412c7d3c2f)