Can someone help me to convert this car movement script from this tutorial to openbor scripting ? I think its very doable but im not sure how to go about it, i converted most of the syntax but im not sure how to use it when applying velocity and angle with drawmethod.
Heres the video on 0:27
Code:
anim follow2
@script
void self = getlocalvar("self");
int sped = getentityproperty(self, "speed");
setlocalvar("vsped",getentityproperty(self, "speed"));
int iPIndex = getentityproperty(self,"playerindex"); //Get player index
void a1 = playerkeys(iPIndex, 0, "attack");
void j1 = playerkeys(iPIndex, 0, "jump");
void right = playerkeys(iPIndex, 0, "moveright");
void left = playerkeys(iPIndex, 0, "moveleft");
float x = 3, y =3;
float speed =0;
float angle =0;
float maxSpeed = getentityproperty(self, "speed");
float acc =0.2;
float dec =0.3;
float turnSpeed =0.08;
if ( a1 && speed < maxSpeed ){
if (speed < 0){
speed += dec;
changeentityproperty(self, "velocity", sin (angle) * acc + speed , cos(angle) * acc + speed);
}
else{
speed += acc;
}
}
if ( j1 && speed > -maxSpeed ){
settextobj(1, 150 , 100 , 1, 1, "-max", openborvariant("elapsed_time")+2000);
if (speed > 0){
speed -= dec;
}
else{
speed -= acc;
}
}
if ( !a1 && !j1 ){
if (speed - dec > 0){
speed -= dec;
}
else if (speed + dec < 0){
speed += dec;
changeentityproperty(self, "velocity", x ,y);
}
else {
speed = 0;
changeentityproperty(self, "velocity", x ,y);
}
if ( right && speed !=0 ){
angle += turnSpeed * speed/maxSpeed;
}
if ( left && speed !=0 ){
angle -= turnSpeed * speed/maxSpeed;
}
x += sin (angle) * speed;
y -= cos(angle) * speed;
}
@end_script
loop 1
offset 22 23
bbox 6 5 83 98
delay 1
frame data/chars/car/car.gif
frame data/chars/car/car.gif
Heres the video on 0:27