How do I shoot from a rotating moving point correctly?

  • I have a player with a Platform behavior and a cannon that rotates towards the mouse and is pinned to the player.

    I want to make the rotating cannon shoot towards the mouse, and I want to adjust the speed of the projectiles it shoots so that they're faster by as much as the player was moving in any direction when they were fired.

    So to be able to adjust for the player's motion, I'm not using the Bullet behavior, I'm using VX and VY instance variables, in hopes of adding player.Platform.VectorX and VectorY to the VX and VY of the bullet, instead of using angle and speed.

    But I haven't gotten to the addition of the player's motion yet, because I don't even have it shooting towards the mouse correctly.

    Here's how I have it now:

    - System - Every tick - Cannon - Set angle towards Mouse.X, Mouse.Y

    - Mouse - On Left button clicked - Spawn projectile on layer cannon.LayerNumber(image point 1)

    - Projectile - On Created -

    =Set VX to cos(angle(cannon.X,cannon.Y,mouse.X,mouse.Y)*pi/180)*Self.Speed

    =Set VY to sin(angle(cannon.X,cannon.Y,mouse.X,mouse.Y)*pi/180)*Self.Speed

    - System - Every tick - projectile - Set position to x:Self.X+Self.VX*dt y:Self.Y+Self.VY*dt

    I thought that should make it shoot the projectiles towards the mouse, but it doesn't. They go straight to the right instead.

  • Here is my attempt (two versions), not sure if it's working as you wanted, but maybe you could make something of it:

    dropbox.com/s/a49o6oay7qzmwcv/PlatformAndBulletSpeed.capx

    dropbox.com/s/23k3fimfyft7jgj/PlatformAndBulletSpeed2.capx

  • pi/180 = a very small number.

    cos(any angle)= mostly less then 1

    cos x pi/180 = even smaller

    Self.Speed must be like 10.000 to have VX resulting in a value of 1 pixel.

    Rounding issues push VX closer to 1 and VY closer to 0.

    Look into the Ghost Shooter Tutorial for a better sollution.

    Another tip: Use Browser plugin > action > Log ... to log VX.

    Press CTRL + SHIFT + i in Chrome's preview window to monitor logged VX.

    Now you can see what is happening with VX.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is my attempt (two versions), not sure if it's working as you wanted, but maybe you could make something of it:

    https://www.dropbox.com/s/a49o6oay7qzmwcv/PlatformAndBulletSpeed.capx?dl=0

    https://www.dropbox.com/s/23k3fimfyft7jgj/PlatformAndBulletSpeed2.capx?dl=0

    YES! That's what I was trying to do. Awesome! Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)