Touch to move makes actor jump to location

Angry_Noobs_EntertainmentAngry_Noobs_Entertainment Member, PRO Posts: 2
edited January 2014 in Tech Support
I have an actor i would like to move side to side depending on where the player clicks. But only on the X axis. The problem I'm having is, with all of the move functions the player will move towards the position but if you click somewhere else then the actor jumps toward that direction. I would like the actor to move whatever speed I set it too, because I plan on using Speed as an upgrade.

This is how I have it set up

Game Attribute
MoveX int

*Actor: Background*
Rule
If touch is pressed

=do

--Change Attribute
---game.MoveX to 1

=else

--Change Attribute
---game.MoveX to 0


*Actor: Player*
Rule
if game.MoveX = 1

=do

--Interpolate
---Interpolate self.position.x to game.Touches.Touch1x
for 2 seconds using a linear function


This works but sometimes the actor basically teleports across the screen where you click. Is this a bug? Or have i set something up wrong?



(The move to, function works but you have to hold down where you want the player to go. I want to be able to click and have it go to that spot, but if i click somewhere else before it finishes moving, it changes direction to the new spot.)

--Move to
---game.Touches.Touch1.x , 60 relative to scene
at a speed of 100






Answers

  • CORE GameCORE Game Member, PRO Posts: 280
    instead of using move try:
    change attribute self.linear velocity X = (negative number to move left , positive to move right.

    if you want you can store the position X of the actor (which is moving) so you can compare it with the device.touch.x and then decided to move left or right as following:

    constrain self.positionX to storedX

    IF storedX > device.touch.x then self.linear velocity X = 100
    IF storedX < device.touch.X then self.linear velocity X = -100
    IF storedX = device.touch.X then self.linear velocity X = 0

    you have many options that including (linear velocity , accelerate, interpolate).

    try and see which one fits your scenario !


  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited January 2014
    You need to use a move to and update the position in the move to behavior. Make two game level REAL attributes and store the current touch there. Address the move to x and y to those attributes and make sure run to completion isn't checked.
Sign In or Register to comment.