This site requires JavaScript, please enable it in your browser!
Greenfoot back
Roshan123
Roshan123 wrote ...

2020/10/22

Collision

1
2
Roshan123 Roshan123

2020/10/22

#
How to make my collision mechanism better....
public void stone()
    {
boolean upKeyDown;
      Actor Stone=getOneIntersectingObject(Stone.class);
      );
   
      if(Greenfoot.isKeyDown("w") && Stone !=null) 
      {
        speed=0;
      }
      if(upKeyDown != Greenfoot.isKeyDown("w") && Stone !=null) 
      {
        move(-15);
      }
Its working but sometimes the actor passes through the blocks
danpost danpost

2020/10/22

#
Roshan123 wrote...
How to make my collision mechanism better.... << Code Omitted >> Its working but sometimes the actor passes through the blocks
When a collision occurs, you should move the actor back off that which it collided with. You may already understand that much; but, you seem to be moving back haphazardly (although I do not see how the actor moved to begin with here). Also, your boolean upKeyDown is probably not what you need.
Roshan123 Roshan123

2020/10/22

#
Also, your boolean upKeyDown is probably not what you need.
If i will not use boolean key then it will simultaneously move back which seems odd I wanted it to work smoothly. That's why i used boolean(but now i want to make it better) Hope u understand my reply well.....
danpost wrote...
Roshan123 wrote...
How to make my collision mechanism better.... Its working but sometimes the actor passes through the blocks
When a collision occurs, you should move the actor back off that which it collided with. You may already understand that much; but, you seem to be moving back haphazardly (although I do not see how the actor moved to begin with here).
I used this so that it will work more better but it was not working(☞ ͡° ͜ʖ ͡°)☞
if(Stone!=null){
int g=getRotation();
if(g>0&&g<90)
setLocation(getX()-2,getY());
if(g>90&&g<180)
setLocation(getX(),getY()-2);
if(g>180&&g<270)
setLocation(getX()+2,getY());.................
}
Roshan123 Roshan123

2020/10/22

#
U have the scenario in which i m trying to make collision more better I named it as test and then u downloaded it to test that AddedtoWorld is working or not...
danpost danpost

2020/10/22

#
Roshan123 wrote...
U have the scenario in which i m trying to make collision more better I named it as test and then u downloaded it to test that AddedtoWorld is working or not...
My Box Collision scenario is updated now. However, I do not think its collision checking will be suitable for your scenario. You will probably need to check for collision twice per act -- once after moving AND once after turning. If an action causes a collision, reverse that particular action.
Roshan123 Roshan123

2020/10/22

#
Do u mean
Stone stone=(Stone)getOneIntersectingObject(Stone.class);
if(stone!=null)
move(new B(counter).reverse().setLength(1));
danpost danpost

2020/10/22

#
Roshan123 wrote...
Do u mean << Code Omitted >>
No. The first thing to realize is that the method with collision checking needs to know whether the actor moved or not (and same for turning). Best is to have (1) moving; (2) turning; and (3) 2x collision checking all in the same method. Something like: a) determine if moving and by how much in which direction; b) if moving at all: i) move; ii) if collision, move back; c) determine if turning and by how much which way; d) if turning at all: i) turn; ii) if collision, turn back;
Roshan123 Roshan123

2020/10/22

#
About (a)'which direction' int g=getRotation (); About turning (c)'which direction', The actor turns every fps If u can't understand then click on Dawn of Tanks Tanks keeps on rotating every fps
danpost danpost

2020/10/22

#
Roshan123 wrote...
About (a)'which direction' int g=getRotation ();
Still -- moving or not. No collision checking needed if not moving. If moving, check collision after move.
About turning (c)'which direction', The actor turns every fps
A separate collision checking is a must, then, after turning.
Roshan123 Roshan123

2020/10/22

#
danpost wrote...
Roshan123 wrote...
About (a)'which direction' int g=getRotation ();
Still -- moving or not. No collision checking needed if not moving. If moving, check collision after move. A separate collision checking is a must, then, after turning.
If(speed=5)
{
if(stone!=null)
move(new B(counter).reverse().setLength(1));
}
Kanutus Kanutus

2020/10/22

#
If (speed=5) is always true! If (speed==5) is not always true ...
danpost danpost

2020/10/22

#
Roshan123 wrote...
<< Code Omitted >>
No. Just
if (stone != null) move(-speed);
Roshan123 Roshan123

2020/10/22

#
Kanutus wrote...
If (speed=5) is always true! If (speed==5) is not always true ...
By mistakenly ...
Roshan123 Roshan123

2020/10/22

#
Finally made!!!!!! @Danpost please go through this Link and give some feedbacks Plz try this......
danpost danpost

2020/10/22

#
Roshan123 wrote...
Finally made!!!!!! @Danpost please go through this Link and give some feedbacks Plz try this......
You are allowing multiple movements per act cycle. That is, if more than one movement key is pressed, the tank will move for each one. So, the rotation value may not correspond directly with the move and collision checking will not quite run correctly. This is causing the tank to glide backwards along a row of stones. Determine a single direction after checking ALL movement keys; then, if moving, set rotation and move one time only. Collision checking will then react properly will needing to move back off a stone.
There are more replies on the next page.
1
2