Spaceship "fighter" movement problem with picture!

0 favourites
  • 4 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hello

    I'd like to do that the enemy's spaceship go toward one of mine object (ship, building ...) and shoot when it close to one. If this ship reach my object need to go forwad in order to do a new attack cycle. So the ship reach this object go forward and if it's far enought have to turn away and back to go to my object (begin again the cycle, re-attack).

    However this idea is not working as I guess the basic movements (bullet, pathfinding ...) unsuitable for this method. I can to do that the npc fire if it's close enought and it's go forward toward the object but the bullet behaviour can't turn away, the patfinding if should turn, the firt thing what do it stop, and just afterthat turn away to object. I drew a picture for the ease of understanding.

    Any idea?

    Red arrow, top right - Enemy ship, npc

    Green dot, center - Object

    Greenish yelow line - Enemy movement

    1. Go forward toward object (I can to do it)

    2. Movement continue meanwhile starting fire (I can to do it)

    3. It reached the object but must not stop, just should to go foward (how?)

    4. Turn away to object like on the picture. Must not stop! (I have no more idea how can I do it ...)

    5. Fire again while reach the object. Same as 2. (I can to do it) (Meanwhile we're in the cycle/turn 2.)

    6. Go throught the object whitout stop. Same 3. step.

    Etc etc... again and again.

    Thank you!

  • You could have the object/attacker alter its course for the bullet behavior when it is close to a given object/target.

    Perhaps measure the distance, and if it is within certain distance, set an instance variable to the opposite angle, and lerp the bullets angle of motion towards the newly set opposite angle (variable).

    event

    distance(attacker.X,attacker.Y,target.X,target.Y) < 100

    sub event

    trigger once

    set var oppositeangle = angle(attacker.X,attacker.Y,target.X,target.Y) - 180

    sub event

    set attacker.bullet.angleofmotion = lerp(self.bullet.angleofmotion, self.oppositeangle, 10*dt)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you!

    It's a good idea and almost working. I had to change some parameters. My next problem with this, that the ship not too precise and not go throught the object every time. I don't know what can it be the problem. Sometimes almost precise, sometimes not. That's why the enemy spaceship fire or hit or not.

    I did some print screem action because I thought it's interesting.

    The lines the ship 'footprint', the red part the 'shoot range'. I did every test 60 second and I didn't change nothing.

    1 Hit, 15 fault

    16 Hit , 0 fault

    10 Hit, 5 fault

    Nothing change among the test, just I click on restrat. I did a lot of test not just three. The result is same. Sometimes not precise with many fault and a lot os test quite precise and some avarge same the third picture.

    Thanks again, the result is not bad, I can use your idea. I'm just curious why can this be...

  • From the images, I would say this is in the initial angle of attack.

    Each attack the angle is slightly increased/decreased, you can see this in the images where the distances between the outer curves vary as you go round clock wise.

    Perhaps look for a way to correct the angle as it goes to get the desired result.

    You could use this difference as a 'skill' attribute for players or npcs

    Also, did you use the lerp, or the anglelerp ? If lerp, perhaps try the anglelerp. (just add angle to your lerp expression)

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