Constrain actor between two values
If I have a drop and drag actor and I only want to be able to move it on the right side of my screen can I constrain its X values to work only between 240 and 480. At the moment I can only get this far:
I have an invisible actor on the left side of the screen called NoGo, it's 240 wide.
When actor overlaps or collides with NoGo
Constrain self.position X to 240.
This stops it going any further to the left but it also locks it to 240 until I let go of the actor and pick it up again.
What I am thinking is if I could constrain it to 240 to 480.
If actor self.position X is < 240 constrain its X value to 240-480.
Or when touch is pressed
Constrain actor self.position X to 240-480.
I tried Min and Max but I don't know how they work, i'm not sure if they are appropriate for this sort of thing.
If anyone has any ideas it will be greatly appreciated.
Cheers,
aaapow
I have an invisible actor on the left side of the screen called NoGo, it's 240 wide.
When actor overlaps or collides with NoGo
Constrain self.position X to 240.
This stops it going any further to the left but it also locks it to 240 until I let go of the actor and pick it up again.
What I am thinking is if I could constrain it to 240 to 480.
If actor self.position X is < 240 constrain its X value to 240-480.
Or when touch is pressed
Constrain actor self.position X to 240-480.
I tried Min and Max but I don't know how they work, i'm not sure if they are appropriate for this sort of thing.
If anyone has any ideas it will be greatly appreciated.
Cheers,
aaapow
Comments
When (all)
mouse is down
mouse.Position.X > 240
mouse.Position.X< 480
Constrain Attribute: self.Position.X To: mouse.Position.X
Constrain Attribute: self.Position.Y To: mouse.Position.Y
(This is untested but might get you close to what you want.)
You can use min and max like this:
Constrain Attribute
self.Position.X To: max(240, min(480, mouse.Position.X))
That way you do not need any invisible actors. A constrain will override the collision anyway.
Hope this helps!
Joe
RThurman
I will test out your suggestion over the weekend.
Cheers.
Firemaplegames
Thanks for posting some insight into using min and max.
This sounds exactly like what I am looking for. I will give it a go.
Greatly appreciated.
Thanks again,
aaapow