Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Can't even finished the first tutorial form the documentation :S

A topic by Q-ro created Feb 18, 2017 Views: 939 Replies: 3
Viewing posts 1 to 4

So i started checking the engine out and following the simple tutorial from the documentation, the platformer one, and everything was ok until it was time to add the collision detection to the game, once added my character wouldn't move at all, not in the slightest, help ? this is how my player behavior looks like:


Sup.ArcadePhysics2D.setGravity(0, 0);
class PlayerBehavior extends Sup.Behavior {

//stores the idle state to transition to when player stops pressing a key
public currentIdle: string;
//How fast the player can go
public _maxSpeed = 0.1;
//The acceleration rate
public acceleration = 1;
//How fast he decelerate
public _decelaration = 0.002;
//Current speed
private _speed = 0;


awake() {

this.currentIdle = "Idle_Dwn";
this.actor.spriteRenderer.setAnimation(this.currentIdle);
}



update() {

Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.ArcadePhysics2D.getAllBodies());
let velocity = this.actor.arcadeBody2D.getVelocity();





if (Sup.Input.isKeyDown("LEFT")) {
// Move the current behavior's actor by a small negative offset on the X axis
//Trying to implement inertia
velocity.x = -0.3;

//Sup.log(`Actor ${velocity}`);
//Sup.Math.clamp(this._speed,0,this._maxSpeed);

//this.actor.move(new Sup.Math.Vector3(-0.1, 0, 0));
this.actor.spriteRenderer.setAnimation("Walk_Left");
this.currentIdle = "Idle_Left";



}else if (Sup.Input.isKeyDown("RIGHT")) {
// Same but positive to go to the right

//velocity.x += this.acceleration;
//Sup.log(`Actor ${velocity}`);

//this.actor.move(new Sup.Math.Vector3(0.1, 0, 0));
this.actor.spriteRenderer.setAnimation("Walk_Right");
this.currentIdle = "Idle_Right";
}else if (Sup.Input.isKeyDown("UP")) {
// Move the current behavior's actor by a small negative offset on the X axis
//this.actor.move(0, 0.1, 0);

//velocity.y += this.acceleration;

this.actor.spriteRenderer.setAnimation("Walk_Up");
this.currentIdle = "Idle_Up";
}else if (Sup.Input.isKeyDown("DOWN")) {
// Move the current behavior's actor by a small negative offset on the X axis
//this.actor.move(0, -0.1, 0);
//velocity.y += -this.acceleration;

this.actor.spriteRenderer.setAnimation("Walk_Dwn");
this.currentIdle = "Idle_Dwn";
}else
{
this.actor.spriteRenderer.setAnimation(this.currentIdle);
}


}
}
Sup.registerBehavior(PlayerBehavior);


I wanted the player to be able to move on a top down perspective, but it won't move on any direction at all

(1 edit)

hi, you have to use the setVelocity() function each time you want to set it (at the end of each if (Sup.Input.isKeyDown)

this.actor.arcadeBody2D.setVelocityX(velocity.x);

without it, your actor doesn't know it will have to move.

don't forget that if you release your finger from the key, your actor should stop, so in your else (for idle position) under the line

this.actor.spriteRenderer.setAnimation(this.currentIdle);

set the velocity to 0.

this.actor.arcadeBody2D.setVelocityX(0);


Hope it helps ;)

Oh god I feel so silly, thank you :P, now I didn't saw that line in the code until you pointed that out.

no problem ;) and don't feel silly lol, sometimes we need an extra eye to point the problem out :) when we are too close we don't see the whole thing.

I'm glad your code is working now.