I'd like to know how to do the control scheme that Star Daze HD did, but also being able to change to go to another position in mid-movement. How do you do this?
-Create a rule - When Touch is outside- -Change attribute - self.position.x to mouse.position.x- -Change attribute - self.position.y to mouse.position.y-
-Create a rule - When Touch is outside- -Change attribute - self.position.x to mouse.position.x- -Change attribute - self.position.y to mouse.position.y-
NO? You would need to do something but interpolate, but not interpolate as it cannot be interrupted.
tenrdrmerMember, Sous Chef, Senior Sous-ChefPosts: 9,934
NextGen said: NO? You would need to do something but interpolate, but not interpolate as it cannot be interrupted.
I'll bet you $100 it Can be.
Check out my demos page There is a specific Cancel interpolate demo and a scene preview that uses interpolate for the preview but cancels it back to the the beginning.
-Create a rule - When Touch is outside- -Change attribute - self.position.x to mouse.position.x- -Change attribute - self.position.y to mouse.position.y-
If you need anymore help just ask.
JamieOneil
As for this. It pains me to say NextGen is correct in one thing. the Change attribute will not give you the effect of a movement. you will need to use move to or interpolate if you want it to move to a point and stop.
There is a problem with using Interpolate. If you tap far away, the player will move very fast. However, if you tap a short distance away from the player, it will move slowly. This is a problem, especially in a dodging game.
tenrdrmerMember, Sous Chef, Senior Sous-ChefPosts: 9,934
Well thats where you have to use math. And work out an expression that will base the time frame on the magnitude between your mouse position and actor.
tenrdrmer said: Well thats where you have to use math. And work out an expression that will base the time frame on the magnitude between you mouse position and actor.
When mouse button down and self.IAmMoving is false --Change Attribute self.TargetX = mouse.Position.X --Change Attribute self TargetY = mouse.Position.Y --Change Attribute self.IAmMoving = true
(Make sure you have an attribute that contains your pixels/second move rate and one that contains the time it should take to move. i.e. self.MoveRate and self.MoveTime)
If self.Postion.X ≠ self.TargetX and self.Position.Y ≠ self.TargetY --Change Attribute self.MoveTime = magnitude(self.Position.X-self.TargetX, self.Position.Y - self.TargetY)/self.MoveRate --Interpolate self.Position.X to self.TargetX for self.MoveTime seconds --Interpolate self.Position.Y to self.TargetY for self.MoveTime seconds
If self.Postion.X = self.TargetX and self.Position.Y = self.TargetY --Change Attribute self.IAmMoving = false
Check out my demos page There is a specific Cancel interpolate demo and a scene preview that uses interpolate for the preview but cancels it back to the the beginning.
As for this. It pains me to say NextGen is correct in one thing. the Change attribute will not give you the effect of a movement. you will need to use move to or interpolate if you want it to move to a point and stop.
CodeMonkey said: When mouse button down and self.IAmMoving is false --Change Attribute self.TargetX = mouse.Position.X --Change Attribute self TargetY = mouse.Position.Y --Change Attribute self.IAmMoving = true
(Make sure you have an attribute that contains your pixels/second move rate and one that contains the time it should take to move. i.e. self.MoveRate and self.MoveTime)
If self.Postion.X ≠ self.TargetX and self.Position.Y ≠ self.TargetY --Change Attribute self.MoveTime = magnitude(self.Position.X-self.TargetX, self.Position.Y - self.TargetY)/self.MoveRate --Interpolate self.Position.X to self.TargetX for self.MoveTime seconds --Interpolate self.Position.Y to self.TargetY for self.MoveTime seconds
If self.Postion.X = self.TargetX and self.Position.Y = self.TargetY --Change Attribute self.IAmMoving = false
I'm trying this, but it's very, very bugged. Sometimes the object flashes, sometimes it stops responding, and sometimes it teleports. Also, at the start of the game it moves to the bottom left.
The object moves faster when it goes diagonally, too.
I had the same problem on Zombie Pond, I wanted the dragonflies to use interpolate (because "move to" was insanely buggy) but I wanted them to move realistically.
Here's what I did:
You will need 4 self attributes (the ones you add on the actor prototype): NewX, NewY, iAmMoving, howMuchTime.
When self.iAmMoving is false --When mouse button is down ----Change Attribute self.NewX to mouse.PositionX ----Change Attribute self.NewY to mouse.PositionY ----Timer after 0.1 seconds ------Change Attribute self.iAmMoving to true ------Change Attribute self.howMuchTime to max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10)) Otherwise --Interpolate self.Position.X to self.NewX for self.howMuchTime --Interpolate self.Position.Y to self.NewY for self.howMuchTime --Change Attribute self.Rotation to vectortoangle(self.NewX-self.PositionX,self.NewY-self.PositionY) (this is a little addendum to make your actor to face towards the direction he is moving) --Timer after self.howMuchTime seconds ----Change Attribute self.iAmMoving to false
MarkOnTheIron said: I had the same problem on Zombie Pond, I wanted the dragonflies to use interpolate (because "move to" was insanely buggy) but I wanted them to move realistically.
Here's what I did:
You will need 4 self attributes (the ones you add on the actor prototype): NewX, NewY, iAmMoving, howMuchTime.
When self.iAmMoving is false --When mouse button is down ----Change Attribute self.NewX to mouse.PositionX ----Change Attribute self.NewY to mouse.PositionY ----Timer after 0.1 seconds ------Change Attribute self.iAmMoving to true ------Change Attribute self.howMuchTime to max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10)) Otherwise --Interpolate self.Position.X to self.NewX for self.howMuchTime --Interpolate self.Position.Y to self.NewY for self.howMuchTime --Change Attribute self.Rotation to vectortoangle(self.NewX-self.PositionX,self.NewY-self.PositionY) (this is a little addendum to make your actor to face towards the direction he is moving) --Timer after self.howMuchTime seconds ----Change Attribute self.iAmMoving to false
That doesn't work either. I click somewhere and half the time the object doesn't respond and the other half of the time it just vanishes. Once it did move, but it vanished afterwords.
I finally solved the problem. The problem is that max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10)) does not work as expected and is probably a bug. Instead of using Interpolate I am using Change Velocity. I used the method in the topic below.
EDIT: There is a bug with the method mentioned above. When you click on the object, it will just fly off screen. You can fix this by placing a rule so that when touch is pressed (NOT if mouse button is down), set velocity to 0.
Comments
-Create a rule - When Touch is outside-
-Change attribute - self.position.x to mouse.position.x-
-Change attribute - self.position.y to mouse.position.y-
If you need anymore help just ask.
JamieOneil
Check out my demos page There is a specific Cancel interpolate demo and a scene preview that uses interpolate for the preview but cancels it back to the the beginning. As for this. It pains me to say NextGen is correct in one thing. the Change attribute will not give you the effect of a movement. you will need to use move to or interpolate if you want it to move to a point and stop.
Good luck
___________________________________________________________________________________
TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!
AppSolute Entertainment on Facebook
AppSolute Entertainment on iTunes
Check it out - it's genius in its simplicity
--Change Attribute self.TargetX = mouse.Position.X
--Change Attribute self TargetY = mouse.Position.Y
--Change Attribute self.IAmMoving = true
(Make sure you have an attribute that contains your pixels/second move rate and one that contains the time it should take to move. i.e. self.MoveRate and self.MoveTime)
If self.Postion.X ≠ self.TargetX and self.Position.Y ≠ self.TargetY
--Change Attribute self.MoveTime = magnitude(self.Position.X-self.TargetX, self.Position.Y - self.TargetY)/self.MoveRate
--Interpolate self.Position.X to self.TargetX for self.MoveTime seconds
--Interpolate self.Position.Y to self.TargetY for self.MoveTime seconds
If self.Postion.X = self.TargetX and self.Position.Y = self.TargetY
--Change Attribute self.IAmMoving = false
Matt
The object moves faster when it goes diagonally, too.
At the top of the behaviors list of the actor, just add change attribute behaviors to set TargetX and TargetY to the position of that actor.
Here's what I did:
You will need 4 self attributes (the ones you add on the actor prototype): NewX, NewY, iAmMoving, howMuchTime.
When self.iAmMoving is false
--When mouse button is down
----Change Attribute self.NewX to mouse.PositionX
----Change Attribute self.NewY to mouse.PositionY
----Timer after 0.1 seconds
------Change Attribute self.iAmMoving to true
------Change Attribute self.howMuchTime to max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10))
Otherwise
--Interpolate self.Position.X to self.NewX for self.howMuchTime
--Interpolate self.Position.Y to self.NewY for self.howMuchTime
--Change Attribute self.Rotation to vectortoangle(self.NewX-self.PositionX,self.NewY-self.PositionY) (this is a little addendum to make your actor to face towards the direction he is moving)
--Timer after self.howMuchTime seconds
----Change Attribute self.iAmMoving to false
________________________________
【ツ】iPhone Icon Pack 【ツ】 - 【ツ】Graphic Pack【ツ】
Free GS demo: High score simple and advanced; Game Center; App Rating System
Want me to send the project file?
http://gamesalad.com/forums/topic.php?id=16441
Works perfectly!
EDIT: There is a bug with the method mentioned above. When you click on the object, it will just fly off screen. You can fix this by placing a rule so that when touch is pressed (NOT if mouse button is down), set velocity to 0.