Forward vector not correctly functioning?

Hi everyone! I’m creating a cannon and have run into some unexpected behaviour;

The 3 cannons on the left work but the rest don’t or have a small offset. I’m using the forward vector of an arrow (which points in the direction the cannon shoots) * by a float (speed) to shoot the cannonball along the current rotation of the cannon;

However, this results in the weird behaviour I’ve shown in the video.

Does anybody have any pointers as to what I’m doing wrong? The arc I generate uses the same method which does work in every direction…

At a glance I’d say there’s Initial Speed and/or Velocity set for the Projectile Movement Component and it gets overriden with the physics call. Since you’re not rotating the actors, the initial Speed / Velocity tries to do its thing and then chaos ensues. A bit of a wild guess, though.

Can you show or explain how the projectiles work? Their hierarchy, too.


Also, must we use explicit physics call for this? Projectiles movement comp simulate it already. And pretty well, too. Do tell.

1 Like

My projectile hierarchy as of right now looks like this:
hierarchy

There’s a small bit of code in the projectile blueprint but that relates to damaging an ai (the upper left cannon shows that).

The velocity on the ProjectileMovement component is set to 0, 0, 0 because I use the ForwardVector of the cannon to shoot it in the correct direction.

And to answer your last question, I’m open to all suggestions. I don’t work with physics too often… So please do tell if you have a better alternative! :slight_smile:

1 Like

And to answer your last question, I’m open to all suggestions. I don’t work with physics too often… So please do tell if you have a better alternative!

Consider the following:

  • this is my CannonBall with an exposed variable:

As soon as the actor is constructed, the Projectile Movement Comp gets that value.

  • this is my Cannon

I feed the projectile with the desired value and have the movement component do all the hard work here.

Any and all physics simulation is disabled here. Essentially:

image

If you try to sim physics and have the movement comp that tries to do the same, one of the systems will give up.

1 Like

Very insightful answer, thanks a lot!
I’ve managed to fix it :slight_smile:

1 Like

An alternative that still does not use physics could look like so:

  • we rotate the projectile first:

  • and Use initial Speed

image

There’s no other script. The end result will be the same.

1 Like

first i would try to disable collision on the cannons, just to see if the cannon balls are colliding with the cannons on launch (physics wont work if you disable collision on the balls)

second i would try what everynone suggested above, just set the rotation of the projectile and use initial velocity,

on my project, i had to add thse 2 IgnoreActor nodes after i spawn the projectile, here CapsuleCollison is your cannon’s collision component, and Self is the cannon