move in fixed increment?
Dooki
Member Posts: 247
Hi there,
I'm working on a top view game. I want my actor(cricket) is 10x10. I want it to be able to move (hop) twice it's size ever time I click in a direction. What attribute would I use? thanks!
-Dooki
I'm working on a top view game. I want my actor(cricket) is 10x10. I want it to be able to move (hop) twice it's size ever time I click in a direction. What attribute would I use? thanks!
-Dooki
Comments
When I applied accelerate or move the actor moves as long as I hold down the mouse. I need the actor to move only a certain amount/value.
Gravity: Since this is a top view game do need gravity?
Thanks again!
-Dooki
Rule
When Mouse is Down
-----Change Attribute: self.Position.Y To: self.Position.Y + 20
Thoughts?
-Dooki
How many directions can the cricket move? 4?
Let's say it is 4: Up, Down, Left and Right.
So if you tap above the cricket, it will move up, if you tap below the cricket, it will move down, etc.
In that case, imagine a giant invisible 'X' placed on the screen, with the center of the 'X' on the cricket.
You now need to determine in which quadrant of the 'X' your Touch is located...
Does that make sense?
So in relation to the cricket:
if the touch is between 45° and 135°, you want the cricket to move up.
if the touch is between 135° and 225°, you want the cricket to move left.
if the touch is between 225° and 315°, you want the cricket to move down.
if the touch is between 315° and 45°, you want the cricket to move right.
To find the angle of the Touch, use VectorToAngle.
Create a new integer attribute in the cricket called 'myTouchAngle'.
Then your Rules in the cricket actor will need to look like this:
Rule
When Mouse is Down
-----Change Attribute self.myTouchAngle To: vectorToAngle(self.Position.X-game.Mouse.X,self.Position.Y-game.Mouse.Y)
-----Rule
-----All
-----When self.myTouchAngle >= 45
-----When self.myTouchAngle < 135
----------Change Attribute: self.Position.Y To: self.Position.Y + 20
-----Rule
-----All
-----When self.myTouchAngle >= 135
-----When self.myTouchAngle < 225
----------Change Attribute: self.Position.X To: self.Position.X - 20
-----Rule
-----All
-----When self.myTouchAngle >= 225
-----When self.myTouchAngle < 315
----------Change Attribute: self.Position.Y To: self.Position.Y - 20
-----Rule
-----All
-----When self.myTouchAngle >= 315
-----When self.myTouchAngle < 45
----------Change Attribute: self.Position.X To: self.Position.X + 20
I hope this helps!
More importantly, I hope you can follow and understand what I did.
Joe
The visual of an "X" is correct. I had to read your rules a couple of times but I get it now. You may not need to know C++ for this but it does take some brain juice to get the hang of this!
Question though:
- I get the four rules for each quad, but is the very first rule in the list a separate rule or are the subsequent four rules within that first rule? Thanks!
-Dooki
I can't see the option for both. I thought maybe you added the "=" in with the numerical value but that didn't work either.
-Dooki
Also, I'd like the actor to jump in the direction where the mouse clicks (or where I touch on the screen) so would I still use when mouse button is down OR when touch is pressed?
Thanks a whole bunch!
-Dooki
So I added a %360 to the vectorToAngle calculation. And I also switched the order of the operands, so instead of self.Position.X-game.Mouse.X it's game.Mouse.X-self.Position.X.
That will bring it back to 0-360.
So the logic is correct, but the angles and signs need to change:
Create a new integer attribute in the cricket called 'myTouchAngle'.
Then your Rules in the cricket actor will need to look like this:
Rule
When Mouse is Down
-----Change Attribute self.myTouchAngle To: vectorToAngle(game.Mouse.X-self.Position.X,game.Mouse.Y-self.Position.Y)%360
-----Rule
-----All
-----When self.myTouchAngle >= 45
-----When self.myTouchAngle < 135
----------Change Attribute: self.Position.Y To: self.Position.Y + 20
-----Rule
-----All
-----When self.myTouchAngle >= 135
-----When self.myTouchAngle < 225
----------Change Attribute: self.Position.X To: self.Position.X - 20
-----Rule
-----All
-----When self.myTouchAngle >= 225
-----When self.myTouchAngle < 315
----------Change Attribute: self.Position.Y To: self.Position.Y - 20
-----Rule
-----ANY <----------------------------------------Be aware of this as well!
-----When self.myTouchAngle >= 315
-----When self.myTouchAngle < 45
----------Change Attribute: self.Position.X To: self.Position.X + 20
So you will have one Rule, with a Change Attribute and 4 other Rules nested within it.
In this case I would use When Mouse is Down - it translates to Touch on a device, but only allows one touch at a time.
That should do it!
OK, I have my actor scooting around like the old frogger game. The problem now is that when I click up the actor moves down. When I click on the right, the actor goes left. What am I doing wrong now?
Mahalo.
Dooki
No, my actor doesn't seem to be rotating.
Thanks!
Dooki