| Pointing to another object |
| Author |
Message |
Gizm0 Senior Member
 Nickname: Gizmo Posts: 55 Joined: 15 Jan 2010

|
Posted: Fri Feb 5, 2010 10:55 am |
|
|
Ok so I have a 2d platform character. His arm and blaster r 1 object. Now I can Get his arm 2 point 2 the mouse. And I can also make his arm stay attached 2 him By using this code //update target to follow object1 position
x = object1.x;
y = object1.y;
So the problem is that his arm stays by his leg not his shoulder. So i just changed the origin of the sprite 2 his shoulder. This didnt work. Can someone pleaz help the little helpless incompetent one? |
|
 |
retrogamer Silver Member
 Nickname: retrogamer Posts: 416 Joined: 04 Mar 2007

|
Posted: Fri Feb 5, 2010 11:27 am |
|
|
| The constants mouse_x and mouse_y are your friends. |
|
 |
Gizm0 Senior Member
 Nickname: Gizmo Posts: 55 Joined: 15 Jan 2010

|
Posted: Fri Feb 5, 2010 11:32 am |
|
|
they r? can u show me what to do?
thanx |
|
 |
CoolGamrSms Platinum Member
 Nickname: CoolGamrSms Posts: 1382 Joined: 27 May 2007

|
Posted: Fri Feb 5, 2010 12:15 pm |
|
|
| retrogamer wrote: | | The constants mouse_x and mouse_y are your friends. |
That wouldn't even make sense if they were constants...  |
|
 |
Gizm0 Senior Member
 Nickname: Gizmo Posts: 55 Joined: 15 Jan 2010

|
Posted: Fri Feb 5, 2010 12:30 pm |
|
|
| well now im confused. |
|
 |
BenRK Titanium V Member
 Nickname: BenRK Posts: 4740 Joined: 20 Jun 2006

|
Posted: Fri Feb 5, 2010 1:20 pm |
|
|
| mouse_x and mouse_y are the x and y variables for the mouse in relation to the game room. |
|
 |
ScoreUnder Gold Member
 Nickname: scoreunder Posts: 737 Joined: 16 May 2007

|
Posted: Fri Feb 5, 2010 4:24 pm |
|
|
| retrogamer wrote: | | The constants mouse_x and mouse_y are your friends. |
"Constant" being another word for "something that stays the same for the entirety of the program". |
|
 |
retrogamer Silver Member
 Nickname: retrogamer Posts: 416 Joined: 04 Mar 2007

|
Posted: Fri Feb 5, 2010 6:12 pm |
|
|
| ScoreUnder wrote: | | retrogamer wrote: | | The constants mouse_x and mouse_y are your friends. |
"Constant" being another word for "something that stays the same for the entirety of the program". |
I meant to say reserved word, you guys know what I mean. It's been a while since I last took a CS course. |
|
 |
ScoreUnder Gold Member
 Nickname: scoreunder Posts: 737 Joined: 16 May 2007

|
Posted: Sat Feb 6, 2010 3:11 pm |
|
|
The word "constant" is fairly everyday, not just limited to computing.
I've never taken any form of CS course. |
|
 |
Gizm0 Senior Member
 Nickname: Gizmo Posts: 55 Joined: 15 Jan 2010

|
Posted: Sat Feb 6, 2010 4:10 pm |
|
|
Ok I got it 2 stay where i wanted by doing this:
//update target to follow object1 position
x = object1.x+or-whatver needed;
y = object1.y+or-whatever needed;
But.....Of course..... THere is another problem. When the character runs, his arm is flying behind him. Same problem when he jumps, falls ext.
So............... um...... maybe........ someone...... could um.......... um...... help..... |
|
 |
retrogamer Silver Member
 Nickname: retrogamer Posts: 416 Joined: 04 Mar 2007

|
Posted: Sat Feb 6, 2010 4:25 pm |
|
|
| ScoreUnder wrote: |
I've never taken any form of CS course. |
I think you should! I'm switching majors from physics to CS. Wish me luck.
| Gizm0 wrote: | Ok I got it 2 stay where i wanted by doing this:
//update target to follow object1 position
x = object1.x+or-whatver needed;
y = object1.y+or-whatever needed;
But.....Of course..... THere is another problem. When the character runs, his arm is flying behind him. Same problem when he jumps, falls ext.
So............... um...... maybe........ someone...... could um.......... um...... help..... |
Try putting that code in the end step event or the draw event, whichever one suits your fancy. |
|
 |
Gizm0 Senior Member
 Nickname: Gizmo Posts: 55 Joined: 15 Jan 2010

|
Posted: Sat Feb 6, 2010 4:42 pm |
|
|
| Yeah i already tried that... apparently it didnt suit my fancy as much as i would have liked... |
|
 |
snowyowl Junior Member
 Nickname: snowyowl Posts: 25 Joined: 13 Jul 2008

|
Posted: Fri Feb 12, 2010 9:30 am |
|
|
| END step event. Not just plain vanilla step event. Double-check it please; this seems the most likely issue. |
|
 |
McTater Silver Member
 Nickname: MastaMcTater Posts: 418 Joined: 13 May 2010

|
Posted: Sun May 30, 2010 3:37 pm |
|
|
| It appears I'm a bit late, but just in case anyone has the same problem... It's the sprites. Change the origin of the sprite to the shoulder in every image of every animation. Somewhat monotonous, but its the only solution I can think of at the moment. |
|
 |
Nighthawk17 Titanium Member
 Nickname: Nighthawk Posts: 2818 Joined: 21 Jun 2006

|
Posted: Wed Jun 2, 2010 4:23 am |
|
|
If you have the registered version, make sure your sprite points right in the sprite editor, set said sprite's origin to the center, and put this code in the step event for the object,:
| Code: | direction=point_direction(x,y,mouse_x,mouse_y);
image_angle=direction; |
If you're unregistered, you'll need four sprites, one for up, one down, one left, and one right:
| Code: | direction=point_direction(x,y,mouse_x,mouse_y);
if direction>315 and direction<=45
{
sprite_index=rightsprite;
}
else if direction>45 and direction<=135
{
sprite_index=upsprite;
}
else if direction>135 and direction<=225
{
sprite_index=leftsprite;
}
else if direction>225 and direction<=315
{
sprite_index=downsprite;
} |
I'm not sure if point_direction() is a pro function or not, but I'm pretty sure that works in GMLite. |
|
 |