INTERPOLATE SUCCESS: Constant speed, stop when you want, and collide with stuff
(scroll down this thread to the first video, to see movement, colliding, changing of direction half way through an interpolate)...
Evening world....
Ok, so my brain doesn't work anymore its official, I'm tired, slow and in need of some shining light to come down and save me (or send me to hell...which ever is quickest and most fun)...
The Problem/Idea...
I'm trying to use interpolate to move an actor from its current position to touch positions on X and Y. Easy....
This I've done and it works as normal.
But I wanted to try and have a constant speed no matter how far you are moving. So not move over any distance at set duration.
I've also got a camera in the scene, with an offset for the touch on x and y to work properly.
I thought I'd be able to use magnitude to get the distance between the actor and the target position and use that to generate the duration which reduces as the actor moves to the target position...But after numerous ideas, formula, attributes it just does'nt want to happen.
I could use Move To, but it can be so buggy and I'm sure there is a way to do what I want with lovely people favorite INTERPOLATE
Any ideas?
Any successes?
I bet theres a friggin button you press and it does it but I missed it in an update... Damn you mind... I'm of to bed... fingers crossed some kind little Elf willl have come and answered a question to help this frail decrepit keyboard tapping geek.
I may just be thinking about the whole thing the wrong way, and could perhaps be interpolating motion velocity or something...basically I want a nice super processor light way to move an actor to touch....
Evening world....
Ok, so my brain doesn't work anymore its official, I'm tired, slow and in need of some shining light to come down and save me (or send me to hell...which ever is quickest and most fun)...
The Problem/Idea...
I'm trying to use interpolate to move an actor from its current position to touch positions on X and Y. Easy....
This I've done and it works as normal.
But I wanted to try and have a constant speed no matter how far you are moving. So not move over any distance at set duration.
I've also got a camera in the scene, with an offset for the touch on x and y to work properly.
I thought I'd be able to use magnitude to get the distance between the actor and the target position and use that to generate the duration which reduces as the actor moves to the target position...But after numerous ideas, formula, attributes it just does'nt want to happen.
I could use Move To, but it can be so buggy and I'm sure there is a way to do what I want with lovely people favorite INTERPOLATE
Any ideas?
Any successes?
I bet theres a friggin button you press and it does it but I missed it in an update... Damn you mind... I'm of to bed... fingers crossed some kind little Elf willl have come and answered a question to help this frail decrepit keyboard tapping geek.
I may just be thinking about the whole thing the wrong way, and could perhaps be interpolating motion velocity or something...basically I want a nice super processor light way to move an actor to touch....
Comments
Whether its down to my scene having a touch offset cause of the camera I'm not sure.
I was using to get the distance.
Magnitude (self position x - touch position with offset x, self position y - touch position with offset y)
Also tried...
Magnitude ( touch position with offset x - self position x, touch position with offset y - self position y - )
I also tried using the distance created and times it/ divided it...
maybe I need to put the distance into a display text field so I can see whats going on...
is it (selfpositionX-TouchX+Offset...
or
is it (selfpositionX-(TouchX+Offset)...
I would always debug with display text.
The camera origin is constrained x and y to an attribute.
Then if touch is pressed
I constrain touch x offset to cam x - touch x)
Same for y
( at least it's something like that, computer is now off and I'm on my phone)
Just for clarification, you wanted a single actor to INTERPOLATE to a position x/y, from it's current position, but whether if it is moving a half an inch, or across the entire screen, you want the speed at which it moves to be the same as if you were using a Move behavior?
The way I did it is as follows.
Game Attributes:
TouchX - Real
TouchY - Real
=====
Actor 1 (The one that will be interpolating) Attributes:
Moving? - Boolean
Time - Real
Speed - Int (Set this to whatever rate at which you want the actor to move)
=====
Actor 1 Rules & Behaviors:
Rule:
When ALL Conditions are valid:
Attribute Self.Moving? is false
Actor Receives Event - Mouse Button is down
Change Attribute - game.TouchX = game.Mouse.Position.X
Change Attribute - game.TouchY = game.Mouse.Position.Y
Change Attribute - Self.Moving? to True
Rule:
When ALL Conditions are valid:
Attribute Self.Moving? is True
Change Attribute - Self.Time = Magnitude(self.Position.X - Game.TouchX, Self.Position.Y - Game.TouchY)/Self.Speed
**This follows the formula of Speed = Distance/Time or in your case Time = Distance/Speed**
Interpolate Self.Position.X to Game.TouchX - Duration: Self.Time
Interpolate Self.Position.Y to Game.TouchY - Duration: Self.Time
Rule:
When ALL Conditions are valid:
Attribute Self.Position.X is Game.TouchX
Attribute Self.Position.Y is Game.TouchY
Change Attribute - Self.Moving? to false.
=======
Again, given that I couldn't really replicate your camera offset and other details, this is what I came up with.
Basically, every time the actor is not moving, wherever the player touches, will be stored into the TouchX & TouchY attributes.
The actor is then allowed to move. But before it moves, we need to figure out how long it should take to interpolate there, given that interpolate uses duration instead of speed.
We calculate the Duration using Time = Distance/Speed or in other words, the Magnitude from the Actors current X/Y to the TouchX/Y divded by the Speed Attribute.
We can then set up to the interpolates, one for X & Y, and for duration, we plug in the Time that we just calculated above.
Once the actor reaches the X&Y of the TouchX&Y, we mark it as no longer moving, and the screen can then be touched again to interpolate to a new spot.
I've set up a working demo and have a single actor moving at various parts of the screen at the same pace no matter how far it travel.
Hope this is what you are looking for!
For the Camera Offset I have done something similar before and I believe what you need to use for your expression is this
`Magnitude(self.Position.X - (Game.TouchX+Game.CameraOffsetX), Self.Position.Y - (Game.TouchY+Game.CameraOffsetY))/Self.Speed`
Obviously you have to create and and constrain the camera origins to those camera offset attributes or do your expression from an unlocked instance. Be sure you get those parenthesis in there right too. Like I said I believe that should work but I have not tested it for this specific task but I have done similar in the past.
Shane that sounds spot on. It makes sense, basically had te same setup but without the speed attribute.
Will try it later
At tenrdrmer, thanks for that. My camera offset was already working. But I'll read through your workings and see how it differs.
Cheers
and it works, so thankyou very much...the speed setting I'm currently using is 100 and that is about right for a walking pace. (Also had to fix my damn camera offset rules, which I've done before for another project fine, but I'd accidentally used constrain when I needed change attribute and it was causing all sorts of crazyness).
Whilst I'm working on it I'l ask, I'm trying to have it so if you click and change the destination mid move it just changes direction etc... but as its interpolate with some bits of formula it gets a little confused and the actor jumps position madly before changing direction. I know it's due to the way interpolate works and the time it takes GameSalad to run the formula I guess...
I'll have a tinker and see what I come up with, but any ideas welcome.
Something like if screen pressed, stop walking and await new directions. When screen is released head to new position. I can see constraining the actors postions to two attributes would work,....Though obviously if it takes too many rules I might as well risk it and use Move To.
Cheers again
Jon
... found this on another thread from one of the Special High Chefs...
Change the destination of the interpolate to the value at which you want to stop it.
a collection of taxing ideas....
...oh just edited my message above.... I need to change the destination for my interpolate to get it to stop....
Not too messy either... I'll share this once I've got it with a few more things going on.
...........
I made the touch x offset save to an attribute called game.destination.X and game.destination.Y
if you press the screen, change 'walk to 0.
in the actor:
if 'walk' = 0
change:
destination X to self.pos.X
destination Y to self.pos.Y
and self.time to 0 (so it does'nt interpolate weirdly to its own position it just gets there straight away)
if you release the screen, change 'walk to 1' and carry on to new destination based on the new destination co-ordinates...
Now I'm trying to master the impossible and make collide work with interpolate... 90% of the way there...I can push blocks around now... and stop myself going through them...
All the actors movement is done with interpolate rather than move or move to, as it is considerably light on the processor.
BASIC SETUP
- Actor moves to touch position,
- actor can collide with walls, and push grey ones.
- actor should rotate to angle of direction.
COOL THINGS
- Actor maintains a consistant speed no matter what the distance (not normal with interpolate)
- Actor can collide with walls (not normal with interpolate)
- Actor can collide and push walls (not normal with interpolate)
- Actor can stop interpolating somewhere and change direction (not normal with interpolate)
Yet To Fix:
- Stil need to fix the rotation to stop it rotating the long way round at times.
Only uses one timer, on the solid non moveable wall, when actor collides with it, it scales up 2 pixels then back down after 0.1 sections to push the actor away, otherwise if you didn't have this the actor would be able to travel through the wall on its second attempt.
I'll upload the project for free when rotation is working perfectly. So people can see what's what..