How to constrain an actor to mouse position with a certain speed?
BasGoodboy
Member, PRO Posts: 310
How to constrain an actor to mouse position with a certain speed?
I'm stuck for this for days. Can't figure it out, tried movement, tried constrain attribute, but with
move to
scene.Camera.Origin.X+game.Mouse.Position.X
scene.Camera.OriginY+game.Mouse.Position.Y
it isn't working smooth,
with constrain attribute
scene.Camera.Origin.X+game.Mouse.Position.X
scene.Camera.OriginY+game.Mouse.Position.Y
it all goes too fast, and i don't know how to make a speedlimit to constraining like this.
Goodboi Gamestudios | Monster Jumper now on the App Store
Comments
Also.. adjusting the Max Speed (in motion section actor) and checking Apply Max Speed to for example 2 (very low) won't work in this.
Goodboi Gamestudios | Monster Jumper now on the App Store
@BasGoodboy -- Perhaps it would be better to separate the cursor movement from the camera movement. The attached demo has two actors. The 'cursor' actor follows the mouse. The 'invisible camera control' actor follows the cursor actor (but with a little bit of lag).
Is this close to the effect you are after?
Always remember constrain overrides physics so any physics attributes in an actor will have no effect. How to keep the physics intact is to constrain the velocity of one actor or attribute to another and use a multiplier to increase the speed. So say,
Constrain self.linear.velocity.x to game.touch. Position.x * 20
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@RThurman, thanks a lot for the example. But this is how far I came already, the thing is, I want to have the speed reduced, at your example and at my game, the speed can be as high as you move your mouse, but I want a lower powered speed at max. So if you drag your touch as fast as possible to the left or right, the actor with the rules must not go so fast, but a certain speed. I am not sure this can be done with constraining tho.. or somehow I must set the mouse speed (touch speed on iPhone) at a max speed.
@The_Gamesalad_Guru thanks, this seems like an option, I didn't knew about the constraining overriding physics, so this explains the problems I have.
I just don't see a solution yet.
The rule you gave me is kind of a mystery for me as a not so good coder,
-What does Position.x*20 mean??
-I can only find self.Motion.Lineair.Velocity.X, this is the same as self.Lineair.Velocity.X i presume?
-I can only find game.touch1, game.touch2 etc, not game.touch, where to find this?
Goodboi Gamestudios | Monster Jumper now on the App Store
@BasGoodboy -- OK, you can adjust the speed by going into the 'invisible camera control' actor and modifying the constrain behavior. Currently it reads:
self.Position.X +((scene.Camera.Origin.X+game.Touches.Touch 1.X)-self.Position.X)*.1
All you need to do is adjust the multiplier (the '.1') to the speed you want. If its going too fast, adjust to '.01'. If its going too slow, adjust it to '.5'.
That sounds very good mate. Sorry for doing all the maths but where can I find the invisible camera control actor?
Goodboi Gamestudios | Monster Jumper now on the App Store
Its the magenta colored actor. Open the instance on the scene. (I originally was going to make it invisible, but decided I better make it transparent instead.)
Of course, in your example haha.. dumb me.
@RThurman this is it man! Thanks a lot lot lot, was only thinking about the mouse cursor which should go slower, but that's impossible of course, since it's controlled by touch.
The big thing is of course the camera should not move faster and should focus on the following actor, very good! Thanks.
Goodboi Gamestudios | Monster Jumper now on the App Store
Great! Glad it will work for you.