shaky

Game Editor comments and discussion.

shaky

Postby NightOfHorror » Sat Mar 31, 2012 1:19 am

I am making a different version of Pong to kill time, but I used this one code
Code: Select all
if(x>PongBall.x) x-=8;
         else if(x<PongBall.x)x+=7;

to make AI, and it works, but then there is the fact that my actor shakes while moving.
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby skydereign » Sat Mar 31, 2012 2:01 am

It's only natural that it would shake. If you think about it, that code will be triggered every frame. Now just say the paddle is pretty much lined up with the ball and the ball's xvelocity is 6, that means every frame the paddle will change direction (jumping back and forth). You can avoid this by making it update its xvelocity twice a second, instead updating its position 30 times a second. Now, two other things. One, I would suggest you use brackets. Since you are still learning the clearer your code is defined, the easier it is for you to find any problems in it. There's a problem called a dangling else, which is just one of several problems you might come across when not using brackets. The other thing is that why would the paddle be able to move faster to the left than to the right?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: shaky

Postby NightOfHorror » Sat Mar 31, 2012 2:06 am

I will try this, oh and by the way, I forgot what you said about this, isn't using physical response in script better than going right to it. I
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby skydereign » Sat Mar 31, 2012 3:22 am

I suggest using script editor for almost everything. Reason being it allows to to do any number of actions per single event, and it provides a uniform way of changing values.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: shaky

Postby NightOfHorror » Mon Apr 02, 2012 9:20 pm

wait, how do you update it only two times a second. I am confused. :oops:
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby Hblade » Tue Apr 03, 2012 12:22 am

use this
Code: Select all
if(x>PongBall.x+2) x-=8;
         else if(x<PongBall.x-2)x+=7;
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: shaky

Postby skydereign » Tue Apr 03, 2012 1:08 am

Hblade wrote:use this
Code: Select all
if(x>PongBall.x+2) x-=8;
         else if(x<PongBall.x-2)x+=7;

If you are going to try this, I'd suggest increasing the distance, and you might compress that into one line of code (not that there would be more efficient, just easier since the one thing you want is compressed into one line).

NightOfHorror wrote:wait, how do you update it only two times a second. I am confused. :oops:

You can do this one of two ways. First is to create an actor variable called timer, and do something like this.
Code: Select all
timer++;
if(timer>=15)
{
    // put your movement code here
    timer=0;
}

Notice how it goes until the 15th frame without updating the position, and that that means it updates twice a second. Of course for this method you want to use xvelocity, since moving 8 pixels every half second is a bad way to play pong. The other method, still using xvelocity, is to create a 500ms timer that repeats.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: shaky

Postby NightOfHorror » Tue Apr 03, 2012 1:51 am

well, one more question for future reference. One, what does ++ do and two, is there an automatic 30 frames a second in GE?
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby NightOfHorror » Tue Apr 03, 2012 2:16 am

last question. Sometimes if I hit the ball, it goes out of the playing area, or it gos in this block that I made in each corner. What is wrong with it. Is it just how I put in physical response. Everything is 1.
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby skydereign » Tue Apr 03, 2012 2:30 am

NightOfHorror wrote: One, what does ++ do

++ increments a variable. So if var is equal to 0, it will increase var by 1. Essentially it is the same thing as doing var+=1; (there is a slight difference though, as it increases the variable after the line is processed).

NightOfHorror wrote: is there an automatic 30 frames a second in GE?

Not quite sure what you mean. gE sets the game to 30fps by default, but you can change it if you want.

NightOfHorror wrote:last question. Sometimes if I hit the ball, it goes out of the playing area, or it gos in this block that I made in each corner. What is wrong with it. Is it just how I put in physical response. Everything is 1.

This probably has to do with your ball moving at too high speeds, and causes it to move through the walls. You can usually limit this by either setting a max speed, or by increasing the size of your walls.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: shaky

Postby NightOfHorror » Wed Apr 04, 2012 1:46 am

I need it when an actor in the game gets ten points it is destroyed. So if the ball hits its wall it gains a point, but at ten is eliminated from the game. I put in a code that destroys them when they get one point. Why isn't it working.
Code: Select all
If(ColorScore.textNumber>=10);
{
DestroyActor("ColorBall");
}
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: shaky

Postby skydereign » Wed Apr 04, 2012 2:29 am

First of all, never use textNumber like that. The only time you should use textNumber is when you are setting it equal to a variable.
Code: Select all
textNumber = var;

Several odd problems have occurred from using textNumber differently (probably because of its type). Instead of using textNumber you should use a real variable (one that you create). Now chances are you want to create an actor variable, that is increased when the ball collides with a wall (that way you can have several ball actors on screen). Also in the event, you'd want to check if it is greater than 10, and if so delete itself. Notice that all of that happens in one event, and doesn't have to use textNumber or any other actors.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: shaky

Postby Game A Gogo » Wed Apr 04, 2012 12:15 pm

NightOfHorror wrote:I need it when an actor in the game gets ten points it is destroyed. So if the ball hits its wall it gains a point, but at ten is eliminated from the game. I put in a code that destroys them when they get one point. Why isn't it working.
Code: Select all
If(ColorScore.textNumber>=10);
{
DestroyActor("ColorBall");
}


you placed a ";" after your if statement
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest