Jump to content


Photo

Ai System


  • Please log in to reply
1 reply to this topic

#1 Petro

Petro

    GMC Member

  • New Member
  • 70 posts

Posted 12 June 2008 - 05:01 PM

In my volleyball game I am making an AI system, but I can't get it to work correctly. I have the part to make it move left and right to hit the ball, but I can't get it to jump at the ball. Here is the code I am currently using in the Step event.

[codebox]{
if ball.x > room_width/2 {
if ball.x < x
{
x -= 2;
}
if ball.y >= x
{
x+=2;
}
{
if ball.y < y
{
vspeed-=8
}
}
}
}[/codebox]


I also have a gravity code in the Step event. I know the problem with this code, it just keeps telling it to go higher and higher because the ball is close to it, but how do I fix it?


--Thanks

Edited by Petro, 12 June 2008 - 05:02 PM.

  • 0

#2 SageFox

SageFox

    GMC Member

  • New Member
  • 114 posts

Posted 12 June 2008 - 05:07 PM

The problem is in
if ball.y < y
{
vspeed-=8
}
This makes the vspeed decrease 8 each step, which, unless you have some very high gravity, will "float off." I suggest you change it with something like this (assuming you use some sort of object for the floor):
if(ball.y < y && !position_empty(x,y+1))vspeed-=8;

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users