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

2019/10/8

One object (car) is hitting another Object(house). House will move after hitting. Car will vanish.

spaceskull spaceskull

2019/10/8

#
i want to know how to make the house move after it gets hit by a car
danpost danpost

2019/10/8

#
spaceskull wrote...
i want to know how to make the house move after it gets hit by a car
What codes do you currently have for car and house?
spaceskull spaceskull

2019/10/8

#
if(Greenfoot.isKeyDown("left")) { setLocation(getX()-1,getY()); } if(Greenfoot.isKeyDown("right")) { setLocation(getX()+1,getY()); } if(isTouching(house.class)) { getWorld().removeObject(this); } this is the code for the car i made it go to the house and than vanish now i want to know how to make the the house move back when the car hits it.
danpost danpost

2019/10/8

#
In the if isTouching block, you will need to create a reference (Object variable) for the hit house:
house hse = (house)getOneIntersectingObject(house.class);
Then you can "tell" (call a method in) the house it was hit. The method may need to be supplied a direction to move and should probably set a counter to some nominal positive value to count move steps down from. The act method in house should check for non-zero counter value. If so, move house in set direction and decrease the counter.
spaceskull spaceskull

2019/10/9

#
thank you so much
You need to login to post a reply.