Back to Blog
Stencyl fire bullet direction of bullet5/17/2023 So in reality, the projectile would not fall straight down as soon as you pull the trigger. So since the bullet takes time to accelerate, when you pull the trigger, the bullet in the chamber will have to speed up to reach –B and cancel out the effects of B. Like the name suggests it is ideal for projectiles like bullets, but it is also useful for automatically controlling other types of objects like enemies which move forwards continuously. However, it provides extra options like gravity and bouncing that allow it to also be used like a bouncing ball. In short, when you pull the trigger, the bullet won’t immediately be traveling at 300km/h in the opposite direction (-B). The Bullet behavior simply moves an object forwards at an angle. First, even if the projectile can travel 300 km/h in the opposite direction (the exact same speed that you are traveling), it will need a bit of time to reach that speed. What would this look like? For an onlooker, someone who is standing still and watching you as you pass by, they will see you take aim and pull the trigger however, the bullet leaving the weapon will appear to fall straight down as the train pulls away from around it (I am assuming that the back of the train is open, and that the observer is located at a space where they can clearly see all of this happen).īut as I mentioned earlier in reality, things are a bit more complicated. If you are traveling at the speed of a bullet and fire backward, the projectile plummets straight down. So the bullet should fall straight down.So you are traveling at +B and you fire at –B.You fire in the opposite direction at 300 km/h.I thought I could fix this with some kind of check when the bullet button is pressed, but I just can't figure it out. If the character is facing left, the bullets shoot right. Example: If the character is facing right, the bullets shoot right. You are traveling along a path at 300 km/h. The bullets work but will only shoot one direction no matter what.There's a boolean variable in there called facingRIght that I'm using to tell the bullet prefab which way the sprite is facing when it's instantiated.Of course, in the real world, there are a few different ways that this could play out (depending on the specific conditions) however, the short answer can be derived as follows: Here's the script that controls my player sprite's movement. I know there's a simple fix out there, but I'm not quite there with my understanding of C# to be able to figure it out on my own. If I change the direction my player sprite is moving before the bullet prefab expires, it will also change direction along WITH the player. Sounds good right? Well there's one small problem. If my character sprite is facing screen left or screen right and I press the fire button a bullet prefab is instantiated and travels in the correct direction and eventually self destructs. But I've run into a problem I can't seem to solve. I have managed to code the character's left/right movement, jumping and his ability to shoot projectiles. The game is a simple 2D side-scrolling shooter. I'm currently working on my first game using C#. I'm a game artist that's trying to make the transition to indie game developer and I've been studying C# and working with Unity for the past 2 years.
0 Comments
Read More
Leave a Reply. |