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

2014/1/13

rotate actor toward a player

sanoy sanoy

2014/1/13

#
how could i rotate an actor so he is facing another actor directly
danpost danpost

2014/1/13

#
The Actor class method 'turnTowards' uses x-y coordinates for the actor to turn towards. If you know the location of the player you wish your actor to turn toward, then...
sanoy sanoy

2014/1/13

#
And if the actor moves constantly
danpost danpost

2014/1/13

#
Then put the 'turnTowards' command in the act method or a method it calls. The act methods of the active world and all actors in that world are called constantly (while the scenario is running).
sanoy sanoy

2014/1/13

#
i mean actor a should turn Towards actor b and actor a stands still while actor b move with keypress
danpost danpost

2014/1/13

#
sanoy wrote...
i mean actor a should turn Towards actor b and actor a stands still while actor b move with keypress
It does not matter which is moving. If either or both are moving, then you must constantly readjust where it is facing.
sanoy sanoy

2014/1/13

#
ok
sanoy sanoy

2014/1/13

#
if i use this code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class oktororck here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class octorok extends Actor
{
    public static int x = 250;
    public static int y = 250;
    /**
     * Act - do whatever the oktororck wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        turnTowards(x,y);
    }    
}
it looks like this[Disallowed URL]
sanoy sanoy

2014/1/13

#
sry the link isnt working, but they all look a different way there is one oktororck in each corner of the world up left looks down left up right looks up left down left look down right down right looks up right
sanoy sanoy

2014/1/13

#
found the problem the image has had the wrong turn
You need to login to post a reply.