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

2018/5/30

I’m making a sort of zombie game

1
2
NervousNeep NervousNeep

2018/5/30

#
Where the Player 1 picks up the gun, uses it to aim, and then fire the bullet which would be shot depending on the guns rotation
danpost danpost

2018/5/30

#
NervousNeep wrote...
So how would you link the direction of the bullet to say another actor called gun
Show code around where a new bullet is added into the world.
NervousNeep NervousNeep

2018/5/30

#
Ok, I will in the morning
NervousNeep NervousNeep

2018/5/31

#
public void shoot() { MouseInfo mouse=Greenfoot.getMouseInfo(); if(Greenfoot.mousePressed(null)) { Bullet newBullet; newBullet = new Bullet(); World world; world = getWorld(); int z = getRotation(); int x = getX() + 67; int y = getY() + 14; world.addObject(newBullet, x, y); } }
danpost danpost

2018/5/31

#
It may be sufficient just to add the following one line after the world.addObject line:
newBullet.setRotation(z);
However, I cannot say whether the gun's rotation is the same as the player's. If they are different, then more Player1 code needs supplied (the entire class preferably -- otherwise this could take a while). Or, maybe you can figure out what to replace z with to make it the rotation of the gun.
NervousNeep NervousNeep

2018/5/31

#
But what if I want my player1 to remain the same rotation, and I only want the gun to rotate
danpost danpost

2018/5/31

#
NervousNeep wrote...
But what if I want my player1 to remain the same rotation, and I only want the gun to rotate
That is why I said to replace z with the rotation of the gun.
NervousNeep NervousNeep

2018/5/31

#
Ah yes, sorry
NervousNeep NervousNeep

2018/5/31

#
It worked, by jut adding the newBullet.setRotaion(z); code
NervousNeep NervousNeep

2018/5/31

#
Could you also help me with another method, where the gun gets attached to the actor and moves with it
NervousNeep NervousNeep

2018/5/31

#
Never mind I got it
You need to login to post a reply.
1
2