I'm trying to find SOME way to keep the player from freezing (not being able to move) or going into the wall.
momentumx is how fast the player is moving toward the wall.
When the player hits the wall they are redirected into the other direction.
bounceloss is how much momentum is lost when the player is redirected off the wall.
--I'm also going to remove the freezeplayer in this script sooner or later.
NPC Code:
//Momentum (Ice) Script by Massokre
if (created){
friction = .005;
//how much the player slows down naturally, or speeds up naturally if you put it in negatives. Don't put it higher than accel unless you REALLY want to experiment.
momentumcap = 2;
//maximum speed
accel = .02;
//acceleration speed
bounceloss = 2;
//speed is divided by this when player hits walls, 1 for no bounce loss, cannot be 0. Division by 0=BAD.
setani cn_walk,;
this.momentumy = 0;
//original y momentum
this.momentumx = 0;
//original x momentum
freezeplayer .3;
this.ice = 0;
timeout = .05;
}
if (playerchats&&strequals(#c,ice off)){
this.ice = 0;
}
if (playerchats&&strequals(#c,ice on)){
this.ice = 1;
}
if (timeout){
if (this.ice = 1){
if (this.momentumx > friction){
this.momentumx -= friction;
}
if (this.momentumy > friction){
this.momentumy -= friction;
}
if (this.momentumx < -friction){
this.momentumx += friction;
}
if (this.momentumy < -friction){
this.momentumy += friction;
}
if (this.momentumy <= 0&&this.momentumy >= -friction){
this.momentumy = 0;
}
if (this.momentumy >= 0&&this.momentumy <= friction){
this.momentumy = 0;
}
if (this.momentumx <= 0&&this.momentumx >= -friction){
this.momentumx = 0;
}
if (this.momentumx >= 0&&this.momentumx <= friction){
this.momentumx = 0;
}
if (this.momentumx = 0&&this.momentumy = 0){
setani cn_idle,;
}
else{
setani cn_walk,;
}
if (keydown(0)&&!this.momentumy<-momentumcap){
playerdir = 0;
this.momentumy -= accel;
}
if (keydown(1)&&!this.momentumx<-momentumcap){
playerdir = 1;
this.momentumx -= accel;
}
if (keydown(2)&&!this.momentumy>momentumcap){
playerdir = 2;
this.momentumy += accel;
}
if (keydown(3)&&!this.momentumx>momentumcap){
playerdir = 3;
this.momentumx += accel;
}
if (onwall(playerx+.45,playery)||onwall(playerx,playe ry+3)||onwall(playerx,playery+1)||onwall(playerx+2 .5,playery)){
if (this.momentumy>=0){
this.momentumy=-abs(this.momentumy)/bounceloss;
}
if (this.momentumy<=0){
this.momentumy=abs(this.momentumy)/bounceloss;
}
if (this.momentumx>=0){
this.momentumx=-abs(this.momentumx)/bounceloss;
}
if (this.momentumx<=0){
this.momentumx=abs(this.momentumx)/bounceloss;
}
}
playerx += this.momentumx;
playery += this.momentumy;
freezeplayer .3;
}
timeout = .05;
}
Edit-- I don't care about vectors.