Constrain to a rotating actor
Hi guys
I have a problem with the main part my hero graphic setup.
I have a bullet that sits on top of a old six shooter gun (So here are 6 empty holes).
I have created a new bullet graphic that sits on top of this gun.
When you tap on the bullet to fire it, the whole graphic of the gun rotates, like it has been fired but the problem I have is that I want the bullet to re-chamber over the hole it was over when it was fired, which since it was, has rotated to another position.
So, the gun sits at x=70 / y=70
The bullet sits at x=70 / y =108
Is it possible to constrain an actor to a point on a rotating actor?
I have a problem with the main part my hero graphic setup.
I have a bullet that sits on top of a old six shooter gun (So here are 6 empty holes).
I have created a new bullet graphic that sits on top of this gun.
When you tap on the bullet to fire it, the whole graphic of the gun rotates, like it has been fired but the problem I have is that I want the bullet to re-chamber over the hole it was over when it was fired, which since it was, has rotated to another position.
So, the gun sits at x=70 / y=70
The bullet sits at x=70 / y =108
Is it possible to constrain an actor to a point on a rotating actor?
It takes a Zombie to know a Zombie!!!
Comments
I can get it to stick to it without the gun sprite rotating but when you fire the bullet (Tap on it) the gun chamber rotates to but the next bullet at the12 o'clock position, this obviously has then moved the empty chamber clockwise so now I need the bullet to appear where it was fired.
Any help would be really appriciated as this bit is holding up my progress...
Thanks guys
It takes a Zombie to know a Zombie!!!
and http://gamesalad.com/forums/topic.php?id=20867 might help.
This diag covers a lot http://gamesalad.com/forums/topic.php?id=19860#post-151044
Thanks for showing me those threads...that's great and I think that will help me out tremendously.
Thanks a million!
It takes a Zombie to know a Zombie!!!
when i say chamber, i mean the entire 6 slot actor
something like
constrain self position x to: game.chamber x + cos(game.chamber angle%360)*40
constrain self position y to: game.chamber y + cos(game.chamber angle%360)*40
|
|
40 is just an arbitrary number i chose. adjust those to make the actor closer or farther from the center of the main chamber.
as for the other 5 bullets,
maybe use the same formulas but (game.chamber angle+45)%360
not sure how well this would all work, but worth a shot. good luck!
It takes a Zombie to know a Zombie!!!
also, for the other 5 bullets, i think if you have the first slot at 0 degrees (to the right). then instead of +45, i think it would be +60. and the others would be +120,+180,+240,+300 in that order
that should do it!
It takes a Zombie to know a Zombie!!!
I have a problem...
I've gone to my first bullet and started to enter your code - CHANGE ATTRIBUTE....then I hit a problem...
Chamber (or my real actors name is 'Right Gold-Six-Shooter-Empty') does not appear in the second window on the CHANGE ATTRIBUTE panel.
I have successfully entered the first part - constrain self position x to: but when I go to GAME/ get actor its not in the drop down...as this only shows attributes set up and not actors...
What am I doing wrong?
It takes a Zombie to know a Zombie!!!
You will need to make a new game attribute to represent the chamber angle
Just make The new attribute real. Name it whatever. I'll just say chamber angle
Then go to Ur chamber actor and constrain game.chamber angle to self.rotation
Then u will have access to the game.chamber angle attribute u need!
I'll give that a go...:)
It takes a Zombie to know a Zombie!!!
nope...nothing is happening.
The bullet is staying at it's 12 o'clock position and not moving around.
I have attached a screenshot from my first level showing the six shooter in the bottom left. The orbs float up, as you can see there is a orange one on screen.
I've set up a REAL attribute called Sixshooter
Here is the constrain instructions I've put on the red bullet (clicked on the red bullet on the scene, not in the actor section)
Can you see where I might have gone wrong?
It takes a Zombie to know a Zombie!!!
U will need to make 3 game attributes total to make this work.
Sixshooter x
Sixshooter y
Sixshooter angle
In the sixshooter actor, constrain game.sixshooter x to self.position x
Constrain game.sixshooter y self.position y
Constrain game.sixshooter angle to self.rotation
Then...
In the bullet actor
Put the rules I told you. What u did wrong up there is that you just added the y manually after the actual attribute. Same with angle. I can tell because its not highlighted in blue.
Also, 12 o clock isnt zero degrees. 3 o clock is zero degrees. 12 o clock is 90 degrees so in the bullet actor u will put
Constrain self.position x to game.sixshooter x + cos((game.sixshooter angle + 90)%360)*40
Constrain self.position y to game.sixshooter y + sin((game.sixshooter angle + 90)%360)*40
This will work if done right. I'm using these same formulas in the game I'm working on now.
Excellent stuff...I'll try that out and let you know
It takes a Zombie to know a Zombie!!!
Thank you so so much
That worked a treat and now all the bullets stay in their original postion as the sixshooter rotates with each shot.
Had to tweak some of the numbers to line up the bullets ver the holes exactly but that wasn't a big problem...all works great now so can crack on with the game again.
Your a star and thank you for working out the formulas...I would have never worked that out!!!
It takes a Zombie to know a Zombie!!!