I am trying to write a little 3D Game where I drive a tank around and shoot things but I just can't figure out the proper way to handle projectiles and collisions. The driving is working great so that's not an issue.
First problem is using an actual Node as a projectile (Area Node with mesh and collisionshape). I can't seem to align the projectile with my cannon (I have the Z set so at least the shell isn't pointing upwards. I instance the shell scene and use
Shot = Shell.instance()
Shells.append(Shot)
Shot.transform = player.ShotStart.global_transform
Shot.PrevCam = playerCam
self.add_child(Shot)
to instantiate and place the shell at the end of my cannon. Then I use
var globdir = Vector3(0,0,1)
var local_direction = globdir.rotated(Vector3(0,1,0), rotation.y)
velocity = local_direction
var col = move_and_collide(velocity)
if col:
print("Collision " + str(col.collider))
queue_free()
to propel the shell. The problems are #1 Shell points sideways instead of the same direction the cannon was facing and #2 shell flies straight and LEVEL instead of at the cannon elevation angle.
Problem #3 is that it reports collision with the ground but nothing about collisions with other things (even though when the shell hits the targets go flying)
Yes I have layers set. Both 3D Render and 3D Physics have 1 - Ground, 2 - Projectiles, 3 - Enemy, and 4 - Scenery
I set the Shell layer to 2, terrain to 1, and the target I'm trying to shoot as 4. The shell flags are 1,3,4.
Even if I move to where the only possible collision would be a 4 I always get layer 1 (terrain) as the collider.
Any help? Or if someone knows of a good example somewhere I'd LOVE to see it.