GamesNewsForumsUsersDevelopersSupport
Reflect Games Forum Index Reflect Games Forum Index
   SearchSearch   MembersMembers   GroupsGroups  Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reflect Games Forum Index - General Help
Post new topic   Reply to topic Page 1 of 2 - Goto page 1, 2  Next
Pointing to another object
Author Message
Gizm0
Senior Member

Nickname: Gizmo
Posts: 55
Joined: 15 Jan 2010

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 10:55 am Reply with quote

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?Question
retrogamer
Silver Member

Nickname: retrogamer
Posts: 416
Joined: 04 Mar 2007

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 11:27 am Reply with quote

The constants mouse_x and mouse_y are your friends.
Gizm0
Senior Member

Nickname: Gizmo
Posts: 55
Joined: 15 Jan 2010

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 11:32 am Reply with quote

they r? can u show me what to do?
thanx
CoolGamrSms
Platinum Member

Nickname: CoolGamrSms
Posts: 1382
Joined: 27 May 2007

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 12:15 pm Reply with quote

retrogamer wrote:
The constants mouse_x and mouse_y are your friends.


That wouldn't even make sense if they were constants... Shocked
Gizm0
Senior Member

Nickname: Gizmo
Posts: 55
Joined: 15 Jan 2010

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 12:30 pm Reply with quote

well now im confused.
BenRK
Titanium V Member

Nickname: BenRK
Posts: 4740
Joined: 20 Jun 2006

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 1:20 pm Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 4:24 pm Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 5, 2010 6:12 pm Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 6, 2010 3:11 pm Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 6, 2010 4:10 pm Reply with quote

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...............Whistling um...... maybe........ someone...... could um.......... um...... help.....Crying or Very sad
retrogamer
Silver Member

Nickname: retrogamer
Posts: 416
Joined: 04 Mar 2007

View user's profile Send private message

PostPosted: Sat Feb 6, 2010 4:25 pm Reply with quote

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...............Whistling um...... maybe........ someone...... could um.......... um...... help.....Crying or Very sad


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

View user's profile Send private message

PostPosted: Sat Feb 6, 2010 4:42 pm Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 12, 2010 9:30 am Reply with quote

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

View user's profile Send private message

PostPosted: Sun May 30, 2010 3:37 pm Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 2, 2010 4:23 am Reply with quote

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.
Post new topic   Reply to topic Page 1 of 2 - Goto page 1, 2  Next
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group