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

2016/5/8

How to make a character move towards another character

FutureCoder FutureCoder

2016/5/8

#
I am trying to make it so that there is a flying character that only moves left and right, move towards the hero following him, but not turning towards character, or moving down, just following him.
danpost danpost

2016/5/8

#
FutureCoder wrote...
I am trying to make it so that there is a flying character that only moves left and right, move towards the hero following him, but not turning towards character, or moving down, just following him.
Something in the form of the following should do:
1
if (hero.getX() > getX()) ... else ...
FutureCoder FutureCoder

2016/5/8

#
Thanks, but it isn't compiling, it is saying 'non-static getX() cannot be referenced from a static context'. What should i do to fix this?
danpost danpost

2016/5/8

#
FutureCoder wrote...
Thanks, but it isn't compiling, it is saying 'non-static getX() cannot be referenced from a static context'. What should i do to fix this?
It is not 'hero', the class; it is 'hero' the actor or instance of the class. You can probably assign its value with something like this:
1
Actor hero = (Actor)getWorld().getObjects(Hero.class).get(0);
FutureCoder FutureCoder

2016/5/8

#
Thank you so much, it works perfectly now.
You need to login to post a reply.