# Hand animations

Get help using Construct 2

### » Fri Dec 30, 2011 5:53 pm

Ok so I was wondering how I would make the hands of my character follow my mouse position a a certain radius of my character. What I mean is, I have my character and my hands in seperate sprites, the hands follow my mouse a bit like a cursor but it can only go a certain distance from my character.
B
2
G
1
Posts: 9
Reputation: 468

### » Fri Dec 30, 2011 5:59 pm

[code]Global Variable HandDistance = 40 // Distance between body and hand in pixel
System: Every tick
-> Hand: set X to cos(angle(Player.X,Player.Y,Mouse.X,Mouse.Y))*HandDistance
-> Hand: set Y to sin(angle(Player.X,Player.Y,Mouse.X,Mouse.Y))*HandDistance[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,336

### » Fri Dec 30, 2011 6:04 pm

[QUOTE=Yann] [code]Global Variable HandDistance = 40 // Distance between body and hand in pixel
System: Every tick
-> Hand: set X to cos(angle(Player.X,Player.Y,Mouse.X,Mouse.Y))*HandDistance
-> Hand: set Y to sin(angle(Player.X,Player.Y,Mouse.X,Mouse.Y))*HandDistance[/code][/QUOTE]

@YANN: You are really into math, arent you?
B
42
S
19
G
12
Posts: 723
Reputation: 13,876

### » Fri Dec 30, 2011 6:17 pm

Wow haha thanks alot Yann
B
2
G
1
Posts: 9
Reputation: 468

### » Fri Dec 30, 2011 6:20 pm

Eh I guess this is in real programming or its in the events ? sorry haha I'm not use to the program yet and is there a window to see code ? cuz I know a bit of javascript from using Unity engine, I didnt look at what language C2 can use yet.
B
2
G
1
Posts: 9
Reputation: 468

### » Fri Dec 30, 2011 6:23 pm

Oh ok I got around in the events haha sorry I dont recognize everything yet haha but thanks realy.
B
2
G
1
Posts: 9
Reputation: 468

### » Fri Dec 30, 2011 6:51 pm

When you get the hang of vector math it's always the same thing

cos(a) gives you an X projection of the unit vector at angle a
sin(a) gives you an Y projection ot the unit vector at angle a

Just have to scale a unit vector by the magnitude (distance) you want it to be and you're done.

(vector and position are almost the same thing... they share common notation)Yann2011-12-30 18:52:47
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,336