targeting Sprite

Get help using Construct 2

Post » Fri Mar 16, 2012 2:28 am

Hello All!

I have a little top down tank with a rotating turret who's angle slowly follows the mouse. Works great! Now I want to implement a target icon that stays directly in front of the turret, but the y axis moves to the mouse position. I want to know when the turret is lined up with the mouse using this sprite.

I have tried a few things, but it doesn't quite work.

I tried:
Every Tick> Sprite Set position Turret ImagepointY(0), Mouse.x
and variants of this. I think I am way off base.

I (think) I need the event to do something like:
Set position of Sprite along Turret Angle at distance(Turret.x, Turret.y, mouse.x, mouse.y

My head hurts...   HELP!
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 16, 2012 10:14 am

Ahh, trig time!

Darn it... 6am... Don't feel like trig!

Here's a simple solution.

Every tick:

Target: set position to turret.x,turret.y
Target: move at angle angle(turret.x,turret.y,mouse.x,mouse.y), distance distance(turret.x,turret.y,mouse.x,mouse.y).

This should do what you want.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Mar 16, 2012 10:38 am

[code]Sprite: set X to turret.X+cos(turret.angle)*distance(turret.x,turret.y,mouse.x,mouse.y)
Sprite: set Y to turret.Y+sin(turret.angle)*distance(turret.x,turret.y,mouse.x,mouse.y)[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Mar 16, 2012 3:29 pm

Thanks Both of you! I took only 1 semester of Trig... Now I wished I had finished!!!!!!
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 16, 2012 3:44 pm

Well... I took none.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Mar 16, 2012 4:44 pm

I dont need to go back to school. Yann is schooling me just fine!   
B
192
S
6
G
7
Posts: 213
Reputation: 10,178


Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, marekmk, Yahoo [Bot] and 1 guest