​​​​Enclosed | Paddle Movement | GAME DEVLOG #1


Enclosed | Paddle Movement | GAME DEVLOG #1

Hey! Ken here

For this devlog I'd love to share with you the paddle movement system.

# Basic Movement

To make an object move across the path I've generated, I implemented the "MoveOnPath" script.  This script handles the logic of moving an object across a path based on transform.Translate function.

this script keeps track of a "positive" (marked green)  & "negative"  (marked red) point position which are used to calculate the direction for transform translation.

For now the object moves towards the positive target when left arrow key is pressed & towards the negative target when right arrow key is pressed. Later when I'll start testing on mobile, the inputs will be based on touch input.

The targets update as the object moves - whenever the object gets too close to the negative/positive target points ('too close' == MinDistanceToUpdateTargets parameter) then the target updates to the next point according to the path which holds a list of the path points.

# Object Rotation

I got an object moving but I also want it to be always rotated to match the path. To accomplish this I am first getting a hold of the current rotation in Euler Angles & calculate the target rotation which is actually just the subtraction of two target positions (positive & negative). Then I calculate the angle of this rotation vector in degrees & apply it to the z value of the current rotation to make it a new target rotation.


Finally I apply the the rotation using Quaternion.Slerp to make the rotation a rather smooth one instead of snapping the object immediately to the new rotation. using _rotationSpeed * Time.deltaTime I can control how fast the paddle will update it's rotation.

# Controlling Multiple Objects

Adding this feature was actually pretty easy - it all depends on the positive/negative targets.

At first the positive point index was 1 & negative point index was 0 and what I mean by that is for example, when the game starts, the positive point position is initialized to the position of the path point in index=1 inside the points list that makes up the path

To control multiple objects so that they wont start at the same place I added an index for the moving object itself as an offset & then on Awake the target points index is set according to the object index:

Now I can achieve an effect for example of a long paddle that is made up of multiple small objects, each with its own index and that way i can make a paddle that follows the path exactly including in corners :

 a paddle made of 17 parts moves across a rectangle corner

a paddle made of 17 parts moves across a rectangle corner

I am planning on making a power up system in the game and this feature of controlling multiple objects can be useful for making such power ups - for example a power up that will spawn a second paddle in parallel to the first one for a short duration of time.

Two paddles with different indexes, 0 & 3

That's it for this update!

Next I'll work on the core game mechanic which is...

BOUNCING

A

🏐🏀⚽⚾🎱

(DUH)

Ken.


Leave a comment

Log in with itch.io to leave a comment.