Angle Facing Logic

Get help using Construct 2

Post » Thu Jul 04, 2013 10:20 pm

Hi everybody, Ill 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 wont 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.
B
10
S
3
Posts: 75
Reputation: 864

Post » Fri Jul 05, 2013 9:10 am

@Jhonathan Ibanez

Install the latest C2 beta and take a look at the RTS template. It may help you.
B
48
S
16
G
9
Posts: 1,097
Reputation: 11,195

Post » Fri Jul 05, 2013 2:49 pm

Thank you for your reply, Ill take a look at that :).
B
10
S
3
Posts: 75
Reputation: 864

Post » Fri Jul 05, 2013 3:28 pm

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.Jhonathan Ibanez2013-07-05 15:28:47
B
10
S
3
Posts: 75
Reputation: 864

Post » Fri Jul 05, 2013 3:39 pm

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....
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Fri Jul 05, 2013 3:50 pm

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.Jhonathan Ibanez2013-07-05 16:00:07
B
10
S
3
Posts: 75
Reputation: 864

Post » Fri Jul 05, 2013 4:32 pm

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.
B
10
S
3
Posts: 75
Reputation: 864

Post » Sat Jul 06, 2013 2:52 pm

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.Jhonathan Ibanez2013-07-06 14:52:47
B
10
S
3
Posts: 75
Reputation: 864


Return to How do I....?

Who is online

Users browsing this forum: newt and 10 guests