Gamepad Right Stick as Crosshair?

Get help using Construct 2

Post » Fri Jan 10, 2014 6:56 am

Hello,

    This is my first post on the forum, and I've been looking around and could not find my answer.

    So, I'm creating a side scrolling shooter, and I have the aim currently following the mouse so when I shoot bullets they go to where the mouse is on the screen.
    
    My objective: Create a cross-hair, or mouse, that is controller by the right stick on a Xbox 360 gamepad. I currently only find how to change the angle of other objects toward the mouse. Help is appreciated.

Thanks :)
B
4
Posts: 2
Reputation: 204

Post » Fri Jan 10, 2014 3:41 pm

An easy way to control a sprite with the analog stick of a gamepad would be to add the custom movement behavior to the relevant object.

Then set its horizontal speed according to the X axis of the right analog stick with the expression "Gamepad(0,2)" and the vertical speed according to the Y axis with "Gamepad(0,3)".

These expressions return a range from -100 to 100, so you should multiply here with the maximum speed value of your object. Also dont forget delta time "dt"!PixelRebirth2014-01-10 15:43:11
B
22
S
6
G
10
Posts: 1,036
Reputation: 7,518

Post » Fri Jan 10, 2014 6:06 pm

it's just as simple without custom movement,
crosshair | set x to self.x + Xaxis*speed*dt
crosshair | set y to self.y + Yaxis*speed*dt
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Fri Jan 10, 2014 7:10 pm

[QUOTE=keepee] it's just as simple without custom movement,
crosshair | set x to self.x + Xaxis*speed*dt
crosshair | set y to self.y + Yaxis*speed*dt[/QUOTE]

Agreed. I'm merely suggesting custom movement for handier expansion of the movement, since the behavior provides useful expressions, conditions and actions.
B
22
S
6
G
10
Posts: 1,036
Reputation: 7,518

Post » Fri Jan 10, 2014 9:10 pm

[QUOTE=PixelRebirth] [QUOTE=keepee] it's just as simple without custom movement,
crosshair | set x to self.x + Xaxis*speed*dt
crosshair | set y to self.y + Yaxis*speed*dt[/QUOTE]

Agreed. I'm merely suggesting custom movement for handier expansion of the movement, since the behavior provides useful expressions, conditions and actions. [/QUOTE]

I'll have to try these both out later today, I couldn't figure it out in the time waiting, so I just made the gun rotate with the rightstick and shoot in the direction it was facing. Then, made the crosshair at the gun position and I put an imagepoint about 200 pixels to the right of the gun barrel so it would act as a crosshair basically.

I just started using this program so I kind of get what you guys said, I'll try my best to figure out what you both told me so I can apply it.
B
4
Posts: 2
Reputation: 204


Return to How do I....?

Who is online

Users browsing this forum: Laurent and 11 guests