How to make a sprite always stay in front of another[SOLVED]

For questions about using Classic.

Post » Tue Mar 09, 2010 9:06 am

I'm making a game that uses mainly RTS Behaviour (although it's not a RTS game), and I need a small sprite to always stay in front of the main character. This sprite is kind of a targeting reticule, so it should always keep the same distance away from the character's sprite and always in it's front, even if the character turns around. I tried a lot of things, but they didn't work...
B
2
G
2
Posts: 16
Reputation: 682

Post » Tue Mar 09, 2010 10:47 am

Just add an Always event that sets this object in front of the player object. Should work.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Mar 09, 2010 10:55 am

The problem is how to make it stay in front. I only managed to make it stay close to the player, because when the player turns around, it doesn't turn together...
B
2
G
2
Posts: 16
Reputation: 682

Post » Tue Mar 09, 2010 11:12 am

I think what you want is something like

Always set Reticle position to:

X: Player.X + cos(Player.Angle) * Desired distance from player
Y: Player.Y + sin(Player.Angle) * Desired distance from player
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Tue Mar 09, 2010 11:18 am

Thanks a lot, Arcticus! :D It worked!
B
2
G
2
Posts: 16
Reputation: 682

Post » Wed Mar 10, 2010 5:16 am

Or you could place it on a layer above.... as it is UI. I always have a UI layer.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Mar 10, 2010 5:20 am

I believe what he meant was, 'How do I make a sprite stay a certain distance from the player in the angle he's facing'

The way its worded could easily be mistaken for, 'How do I make one sprite always appear on top of another'

However in this case I would also recommend putting it in a UI layer above the game layer anyway so, for example, the aiming reticle doesn't get hidden by some wall you added later.
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Fri Dec 06, 2013 6:50 pm

the formula doesnt seem to work when the player is being flipped with the mirror function
B
22
S
7
G
1
Posts: 270
Reputation: 2,674


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests