Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 10:21:44 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogsdashinobi: quest for a pixel-perfect platformer
Pages: [1]
Print
Author Topic: dashinobi: quest for a pixel-perfect platformer  (Read 381 times)
bombjack
Level 3
***

That's me :)


View Profile WWW
« on: October 16, 2017, 10:09:33 AM »

Dashinoby will be a game about a ninja killing demons Wink
Not much more about it yet.
Logged

bombjack
Level 3
***

That's me :)


View Profile WWW
« Reply #1 on: October 16, 2017, 10:10:05 AM »

At first I'll do my best to create a pixel-perfect platformer.
By pixel perfect I mean that every movement can precisely specified in pixel.
Most of the unity examples I found where using the physics engine.
I'd prefer to avoid it. So I'll wrote those post if it could help someone like me Smiley

I'll use Prime31 CharacterController2D for the base movement. (https://github.com/prime31/CharacterController2D)
Once added the CharacterController2D script, it's important to make sure the RigidBody2D is Simulated and that the GravityScale is set to 0.
If not, you'll run in trouble if you try to have both trigger and collider.

« Last Edit: October 16, 2017, 10:59:44 AM by bombjack » Logged

Penguinoccio
Level 0
**



View Profile
« Reply #2 on: October 16, 2017, 10:13:35 AM »

letter perfect will come later, after all the pixels are done
Logged
bombjack
Level 3
***

That's me :)


View Profile WWW
« Reply #3 on: October 16, 2017, 10:19:22 AM »

letter perfect will come later, after all the pixels are done
Yes Smiley I just wrote it too fast before checking it
Logged

bombjack
Level 3
***

That's me :)


View Profile WWW
« Reply #4 on: October 16, 2017, 10:57:03 AM »

Let's talk about movement
The naive approach is to add the speed to the current velocity and multiply by the deltaTime in order to define a number of pixel per second.
The character is directly at max speed and stop as soon as the button is released.
It doesn't feel quite natural.



public float speed=1.92; // 192 pixel per seconds divided by the number of pixel per unit
void Update () {
  var velocity = ctrl.velocity;
  if (Input.GetKey(KeyCode.LeftArrow) ) {
    velocity.x = -speed;
  }
  if (Input.GetKey(KeyCode.RightArrow)) {
    velocity.x = speed;
  }
  ctrl.move(velocity * Time.deltaTime);
}


A better approach is to add acceleration and deceleration ratio to give a more natural feel.
It's interesting to have separate accel and decel instead of a common ratio to allow ice-like behaviour if needed.



public float accel = 0.15f;
public float decel = 0.15f;
void Update () {
  ...
  if (Input.GetKey(KeyCode.LeftArrow) ) {
    velocity.x = accel * -speed + (1-accel) * velocity.x;
  }
  if (Input.GetKey(KeyCode.RightArrow)) {
    velocity.x = accel * speed + (1-accel) * velocity.x;
  }
  if (!Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.RightArrow)) {
    velocity.x = (1-decel) * velocity.x;
  }
 ...
}


Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic