Character controlled by WASD pointing towards mous

Get help using Construct 2

Post » Tue Feb 26, 2013 12:29 pm

So I'm trying to make a 2d game where you control the character with WASD but he points towards where the mouse is. How do I do that?
I've checked out the "Diablolike-movement" guide and thats almost what I want. Just that I want the sprite to look towards the mouse and move with WASD, not by clicks.
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Post » Tue Feb 26, 2013 12:40 pm

Well, moving the character and facing it toward mouse are 2 different things so i think you have no problem with that.
Once you have the wasd moving, make the following action:

System, on Every tick, Sprite(character) Set angle toward (Mouse.X, Mouse.Y)

NB. You should have added mouse plugin to use that Mouse.X/Y expression

Hope that helps yaPakost2013-02-26 12:41:31
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Tue Feb 26, 2013 12:53 pm

But doesn't that make the result that's in the "Ghost shooter" example? Because that's not what I want. Here's a little pic example:
condolent2013-02-26 12:54:27
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Post » Tue Feb 26, 2013 1:08 pm

You would set different animations for each way he is looking. then sya that when the mouse is between X degrees he is using the certain animation set to looking at that direction.

hope that helped!
B
7
S
2
Posts: 18
Reputation: 891

Post » Tue Feb 26, 2013 2:18 pm

I'm a bit noobish on this so I understood like 1% of that :P
Can my make an quick .capx file with comments explaining a bit further? That would be very helpful!
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Post » Tue Feb 26, 2013 3:16 pm

Ill try to explain this
You have conditions and you have actions
It works like: If (condition), then (action)

In your case i would do the following

Attach an empty sprite to the position of the character
Set action that Sets angle toward Mouse.X/Mouse.Y
Now you have the emty sprite rotating toward the mouse
If the 8 directions of the character are 8 different animations, then set the following event:
IF: System, Every tick /THEN: "Character sprite" Set Animation
and in Animation tipe "round(EmtySprite.Angle/45)"
that makes the angle from 0 to 44 = 0, 45 to 89 = 1, 90 to 134 = 2 and so on.
So now when the angle is within 0 - 44 you get 0, which is animation 0
Hope you understand it
BTW i dont know if thats the best way but i'm just trying to help.
Cheers

Pakost2013-02-26 15:17:24
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Tue Feb 26, 2013 3:36 pm

Didn't work :(
https://dl.dropbox.com/s/b3qupmzj2twr8zq/test.capx?token_hash=AAHT0YRebNbIeGtfYygygwjNKAzRqYt13i2xOUav02bkpw&dl=1
What did I do wrong? Can you edit and add comment on where if you find the error??condolent2013-02-26 15:37:46
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Post » Tue Feb 26, 2013 3:50 pm

Yup my bad
It works with frames but don't seems to work with animations
Anyways here is the solution... its kinda clumsy but still works

https://dl.dropbox.com/u/19082408/123.capx

I have started it you should finish the rest

B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Tue Feb 26, 2013 4:10 pm

Thank you so much!
Now I finally understand :D
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Post » Wed Feb 27, 2013 12:07 pm

Now my next question (don't know if it's possible at the moment):
I tried to make him fire bullets when holding down left mouse button. Bullets are spawning correctly (1 per 0.35 sec).
But when I tried to make them go at different directions for when he's facing another way, they just change everytime my mouse moves and character switches animation.
I added "angle of motion" on every direction event, this is how the event sheet looks like:


Download a .capx here if you're OP:
https://www.dropbox.com/sh/c08d30hn4j6azci/i0AgKCgZYy
Website Twitter Indie Developer
B
20
S
5
G
4
Posts: 201
Reputation: 2,884

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests