Okay, so here is what I got going on -
I have my enemy tank, which is stationary, and I’m trying to get it to fire at the user_tank.
One method that was suggested to me was to fire a continuous stream of invisible bullets towards the user and if one hits the user, then call a function to fire a real bullet - that way the enemies won’t be firing all over the place, hitting the walls&barriers etc…
The problem is that my invisible bullets aren’t reacting to the physical environment (walls, barriers etc…) they are going straight through everything until they hit the user_tank and are removed.
You’ll see that my Ebullet1 is a sensor, that is because every time one of the enemy-tank’s bullets would collide with my user_tank it would cause it to jump a little.
This is the code I am currently using to fire a bullet from the enemy tank:
[lua] function shootEbullet()
local pt = mathapi.rotateAboutPoint( {x=enemyT01.x,y=enemyT01.y-65}, enemyT01, enemyT01.rotation - 90 )
local Ebullet1 = loader:createSpriteFromSHDocument(“FireBall”, “GameFX”, “LevelAssets.pshs”);
– Ebullet1:scale(,);
Ebullet1.x = pt.x; Ebullet1.y = pt.y;
physics.addBody( Ebullet1 , “dynamic”, { friction= 0, bounce= 1.0, density= .6, radius= 7 } );
Ebullet1.class = “bullet”
Ebullet1.isBullet = true
Ebullet1.myName = “Ebullet”
Ebullet1.isSensor = true
Ebullet1.rotation = enemyT01.rotation
Ebullet1.isVisible = false
Ebullet1:applyForce( pt.x - enemyT01.x, pt.y - enemyT01.y, enemyT01.x, enemyT01.y )
level1group:insert( Ebullet1 )
transition.to( Ebullet1, {
time = 800,
x = user_tank.x,
y = user_tank.y,
onComplete = shootEbullet } );
–==================== ‘removeSelf’ functions for various objects–====================
function fireRealBullet()
----
----
print(" Fired Real Bullet ")
end
–==================== Collision Handling–====================
local onEbullet1Collision = function( self, event )
if event.phase == “began” then
if event.other.myName == “Ubase”
or event.other.myName == “Uturret”
then
print(" Hit PlayerTank ")
self:removeSelf()
self = nil
timer.performWithDelay( 10, fireRealBullet)
end
end
end
Ebullet1.collision = onEbullet1Collision
Ebullet1:addEventListener( “collision”, Ebullet1 )
end
Runtime:addEventListener( “enterframe”, shootEbullet )
tmr = timer.performWithDelay(2000, shootEbullet, -1); [/lua]
I’d appreciate any tips someone might have.