Angle Facing Logic

0 favourites
  • 8 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • Hi everybody, I�ll try and go straight to my problem.

    A bit of context: I have a golem turret object (it is a sprite object, it has turret behaviour). These golem turrets appear when I click in the screen (for now). These turrets shoot rocks at the enemy (sprite object) which appers randomly in the screen and takes a journey toward a randomly defined path (pathfinding).

    Objective: the golem "faces" the enemy it is shooting at depending on the position of the enemy (if we center our origin point at the current position of the tower then, if the enemy forms a 45 degrees angle with its position and that of the turret, and we assume clockwise angle as usual, then the golem faces front-right)

    Note: I already have the frames to simulate the golem facing.

    Problem: when I use the angle function (my golems have an instance variable named "Aim" which registers the angle formed between the position of the enemy and the golem), lots of enemies appear and lots of golems are placed, the golem seems to be unable to "choose" wich enemy "forms" the angle and won�t change its frame to simulate the facing behaviour.

    Note: I already tried something like:

    System every tick

    golem has target -> golem Aim set value angle(enemy.x,enemy.y,golem.x,golem.y)

    [sub event]

    //logic to change frame depending on the angle formed

    Sorry about my english, I know it is not the best. Any help would be appreciated.

  • jhonathan Ibanez

    Install the latest C2 beta and take a look at the RTS template. It may help you. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Thank you for your reply, I�ll take a look at that :).

  • Something I did not mention is that I do not want to use the rotation of the turret behaviour, this is because even though I want to take advantage of features like: Predictive Aim, On shoot, etc. I want my game to have a senital perspective, so allowing my turret sprites to rotate would have a funny look on them and that is not what I want.

  • If you want to use the predictive aim, you will have to let the turret aim for itself, thus allowing the rotation. If you want to have a similar behavior but with no rotation, I think you're going to have to write the aiming yourself.

    It's only a mater of maths though.

    PredictiveX = targetX + targetSpeedX*bulletTimeToHit

    Where bulletTimeToHit = distance(target,Golem)/bulletSpeed

    Just use this (and same for Y) to set your aiming, and do the shooting yourself. This way you can aim your golem without problem, use the turet behavior for target acquisition and shoot cooldown (the automatic trigger On Shoot), and even make your golem dance while he shoots. Ok, that last bit isn't essential....

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well I managed to somehow trick that, and that is not the problem.

    Trick: if this could be called a trick..., what I did was to put another object called AbstractTurret (not the best name, I know) but without a sprite on it so it is "invisible", on top of the actual turret sprite (golem), this is rotating and using the turret behaviour, that way I use the predictive aim feature.

    The problem is that I want the actual golem sprite to "face" the enemy (sprite animation that is only played, frame by frame, if the enemy is on range) according to the angle formed between the two of them (golem and enemy).

    Note: I do not know yet if my "trick" I the worst practice ever!, but it works, I looks like the golem is actually shooting, looks nice, and logically filled my needs. If this approach is not criticized may be I ll create a manual (do not know if this is worth it, but could come in handy for some guys as lazy as me :P and who do not want to write some code even if programmers like myself xD)

    Again, I apologize for my english :S :P.

  • I think the solution to my problem is actually pretty simple, Ill try something I just come up with a minutes ago this night, and if it works, I ll let all of you guys know. Wish me luck :P.

  • Hi everybody.

    As I expected, it worked!!. It was pretty simple to solve (silly me...), I do not know if all of you guys who might have read this topic are saying "gosh that is so simple, this guy is just so noob", but if you dont, and in the other hand you have the same problem I had, please tell and I ll create some tutorial or something.

    Anyway, I managed to solve the problem of angle facing with senital frames animations (so my game could have some kind of a senital perspective of course), and without losing the predictive aim features of turret behaviour by dividing the logic of turret behaviour from the sprite animation, in other words, I created a dummy object (sprite object) that will be actually implementing the turret behaviour with no sprite at all (so it looks invisible and I know I can make it visible/unvisible with a property) and another object that will have the actual turret sprite. When you do that, the golem wont rotate (while the actual turret will) and it will look like the golem is shooting to the desired direction but with no funny rotating animation.

    I could add more details but I think that it would be better understood with a tutorial, so please, let me know!. Thank you everybody.

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