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

2017/11/30

Actor - gravity, stop on block.

RevoltecX7 RevoltecX7

2017/11/30

#
I want ask u people, when me - as player fall down in 2D world. How to make to stop actor on some block? Thanks for any help. :)
RevoltecX7 RevoltecX7

2017/11/30

#
For better imagination. I want create block with (for exam.) black-border and inside will be another color. And when my actor hit this block. Actor will stop fall down. Or second option, when my actor will fall to ANY picture, how to make it, to stop fall down?
Super_Hippo Super_Hippo

2017/11/30

#
If the block is an actor, you can do it like this: - move the player down - if it is touching a block --- move it back / move it up until it doesn't touch a block anymore If the block is just a part of the background and no actor, you can do the same thing but instead of touching you need to compare the color of the background to the location of the actor after moving.
RevoltecX7 RevoltecX7

2017/11/30

#
It's bad idea, when u have function for fall down and then move it up... or no? U can do it better, when u will use function for control - if he will fall or not fall down. And i just don't know syntax, how to write it to my code. :) I am newbee
Super_Hippo Super_Hippo

2017/11/30

#
No, you wouldn't see it. You only see the actor at its location after the whole act method (in fact, the act methods of the active world and all actors inside them). So for example if your act method looks like this:
1
2
3
4
5
public void act()
{
    setLocation(getX() + 5, getY());
    setLocation(getX() - 5, getY());
}
Then you will not see the actor moving because it ends up being where it started.
RevoltecX7 RevoltecX7

2017/11/30

#
I know i wouldn't see it. But in procces and logicaly it's stupid think - when actor still falling and some ground give him up... It's useless step.
RevoltecX7 RevoltecX7

2017/11/30

#
I know what i want to do. (I want make gravity = false, when he step on any block). But i don't know of this function, how to write it... IN PROCESS: -Actor(player) will step on Actor(block) -gravity = false -Actor(player) will be able to move right/left. And now i just need syntax-code of-> if under actor(player) is specific block <-
Super_Hippo Super_Hippo

2017/11/30

#
It is not stupid and it is not useless. If your actor is not moving only one cell per act, there is a chance that it ends up in the middle of the block. Then you need to move it outside the block again. The alternative would be to check all cells between the current cell and its target cell and if there is a block, you can directly calculate where the actor would touch the block and move it there. But that has the same result, but is far more complex.
RevoltecX7 RevoltecX7

2017/11/30

#
But tell me please, how to check , if block is under me. Specific code, which i need to use xD
Super_Hippo Super_Hippo

2017/11/30

#
Try the isTouching method.
RevoltecX7 RevoltecX7

2017/11/30

#
Thanks
You need to login to post a reply.