Hey, I am not sure if I can explain my problem properly, but I will try my best.
So I have 2 actors named Weapon and Player, my Player actor works as I want to: moves by WSAD and rotates towards my mouse. And now the Weapon actor: rotates towards mouse and follows Player coordinates, but I want it to have little offset from the Player, so it looks like the Player is holding it in right hand, but when I rotate the Player, the offset makes it look weird. I am really sorry, that I can´t explain it more proffesionally, hope you understand me, if anything is unclear, just ask me, I really appreciate your help. THX :D
Player code:
Weapon code:
public class Player extends Actor
{
static int mouseDirection;
static int playerX;
static int playerY;
public void act()
{
MyWorld.bulletSpawn++;
playerX = getX();
playerY = getY();
MouseInfo mouseposition = Greenfoot.getMouseInfo();
if (mouseposition != null) {
turnTowards(mouseposition.getX(), mouseposition.getY());
Player.mouseDirection = getRotation();
}
if(Greenfoot.isKeyDown("w")) {
setLocation(getX(),getY() - 2);
}
if(Greenfoot.isKeyDown("s")) {
setLocation(getX(),getY() + 2);
}
if(Greenfoot.isKeyDown("a")) {
setLocation(getX() - 2,getY());
}
if(Greenfoot.isKeyDown("d")) {
setLocation(getX() + 2,getY());
}
if(Greenfoot.isKeyDown("space") & MyWorld.bulletSpawn > 20) {
MyWorld.bulletSpawn = 0;
getWorld().addObject(new Bullet(), getX(), getY());
}
}
}public class Weapon extends Actor
{
public void act()
{
setRotation(Player.mouseDirection);
setLocation(Player.playerX + 15, Player.playerY + 10);
}
}
