Bullet behaviour angle not rotating when firing

I’ve created a code to rotate a gun I’m using for my game. Here’s the code:
When:system/listener/key pressed/“A”
Do:Pistol/Angle/rotate counter clockwise overtime
When: system/listener/key pressed/“D”
Do:pistol/Angle/rotate clockwise overtime

The problem is that when I rotate the pistol and shoot, the bullet behaviour doesn’t move to the location the pistol is pointing to. It moves forward as if the pistol didn’t even rotate. How yo fix this problem ?

2 Likes

@Thebeast the actual issue is that in the bullet behavior, the direction of movement is fixed. In other words, you have to code the movement of the bullet when it is fired from the gun.

In this case, let’s assume that the gun fires the bullet upon clicking a trigger. So for the code to work, firstly you have to add the bullet object to a BULLET class, and then add the following events:

When: Trigger > Sensing > Touch Down
Do: Gun > Clone > Clone Object > Bullet

When: All in class Bullet > Sensing > Seen > Yes
Do: Affected object from Class Bullet > Movement > Move Forward over time > 5

You can also change the speed as per your wish.

Hope this helps. :slight_smile::slight_smile:

1 Like

I think @Ready and other users including @Dravin, @auntiel, @greenreader9, @poweringbaconmaker might also be able to help you out

1 Like

I agree with @samsajwani1234, this seams correct. Right now, you have 2 separate objects. The bullet and the gun. You have an event to shoot a bullet and to rotate the gun, however, you do not have a event to rotate the bullet and fire it in a different direction. So although your gun is rotating, your butter is not firing in the correct direction as it does not know which way the gun is facing. So as @samsajwani1234 said, you need to basically tell the bullet which way to shoot in relation the the guns direction. Good Luck!
Hopefully I did not make this more confusing.

2 Likes

@greenreader9 You did not.

Actually, you added some more details to what I said earlier.

1 Like

@Thebeast you might need to know this, if you are making a game that involves cloning and destroying something, then the bullet behavior can be easy to use if the direction of movement remains constant.

1 Like

Awesome, I thought I was just speaking confusing jibberish :grinning:

1 Like

Hi @Thebeast ! :metal:.

Also look this example project: https://ready.app.link/clReEnwk6O

ShootLogic

You can improve this logic for your project, I hope it helped you!

Also you can look this small examples (GIF):

Gun Controller:

1 Like

Thank you so much for the help. It worked :slight_smile:

2 Likes

Thanks ready. This example project really helped in fixing this problem

2 Likes

Thank you so much. It worked :slight_smile:

2 Likes

No problem @Thebeast :slightly_smiling_face::slightly_smiling_face:. Glad to help you!