I’ve created a code to rotate a gun I’m using for my game. Here’s the code:
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 ?
@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.
I think @Ready and other users including @Dravin, @auntiel, @Greenreader9, @poweringbaconmaker might also be able to help you out
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.
@Greenreader9 You did not.
Actually, you added some more details to what I said earlier.
@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.
Awesome, I thought I was just speaking confusing jibberish
Hi @Thebeast ! .
Also look this example project: https://ready.app.link/clReEnwk6O
You can improve this logic for your project, I hope it helped you!
Also you can look this small examples (GIF):
Thank you so much for the help. It worked
Thanks ready. This example project really helped in fixing this problem
Thank you so much. It worked
No problem @Thebeast . Glad to help you!