Jump to content


Photo

Strategy game (move object(s))


  • Please log in to reply
12 replies to this topic

#1 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 01 January 2011 - 06:29 PM

Hello.

Here is a question: How let objects move to a point in a strategy game (mouse clicks, and a object go (not go from a point to another point (direct), but go from one point to another (go as you can go with the function/button "move fixed").


hope you can help me.
  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 01 January 2011 - 08:02 PM

Here is a question: How let objects move to a point .... (mouse clicks, and a object go ... from one point to another)

:GM004: ?

Just remember the mouse-click position ins the instance itself and use those in the above command.
  • 0

#3 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 01 January 2011 - 09:27 PM

Here is a question: How let objects move to a point .... (mouse clicks, and a object go ... from one point to another)

:GM004: ?

Just remember the mouse-click position ins the instance itself and use those in the above command.



Thanks, exactly that I want to have.
  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 01 January 2011 - 09:28 PM

Thanks, exactly that I want to have.

You're welcome. :)
  • 0

#5 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 03 January 2011 - 12:59 PM

How do I get it to stop when it gets to the point the user pressed (can not it this way)?
  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 03 January 2011 - 01:49 PM

How do I get it to stop when it gets to the point the user pressed (can not it this way)?

Set speed to Zero and do not execute that "move towards point" command anymore.

The easiest way is to check if you are near to the goal (use "point_distance(...)") to determine if you should stop.


Another way is to change the "speed:" in that command depending on the distance you still need to go :
min(point_distance(x,y,TargetX,TargetY),3)
The "TargetX" and "TargetY" need ofcourse to be replaced with the same variables as you sued for the "X:" and "Y:" arguments, and the "3" should be replaced what you currently have as the "speed:" argument

Hope that helps.
  • 0

#7 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 03 January 2011 - 06:14 PM


How do I get it to stop when it gets to the point the user pressed (can not it this way)?

Set speed to Zero and do not execute that "move towards point" command anymore.

The easiest way is to check if you are near to the goal (use "point_distance(...)") to determine if you should stop.


Another way is to change the "speed:" in that command depending on the distance you still need to go :
min(point_distance(x,y,TargetX,TargetY),3)
The "TargetX" and "TargetY" need ofcourse to be replaced with the same variables as you sued for the "X:" and "Y:" arguments, and the "3" should be replaced what you currently have as the "speed:" argument

Hope that helps.



Did not quite understand what you meant.
  • 0

#8 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 03 January 2011 - 09:35 PM

Did not quite understand what you meant.

Which part ? Suggestion #1 or suggestion #2 ? And what do you not understand ?
  • 0

#9 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 05 January 2011 - 01:53 PM

Did not quite understand what you meant.

Which part ? Suggestion #1 or suggestion #2 ? And what do you not understand ?

Suggestion #1 and #2: Not understand how I shall use it.
  • 0

#10 nukemaster

nukemaster

    GMC Member

  • New Member
  • 268 posts

Posted 05 January 2011 - 03:29 PM

In the step event for your object

:GM073: If point_distance(x,y,TargetX,TargetY) more than 8
:GM004: Move towards TargetX,TargetY at speed 4
:GM064:
:GM002: No direction (Set speed to 0)

For the first action, the variable you are checking is
point_distance(x,y,TargetX,TargetY)
TargetX and TargetY are the x and y co-ordinates of whatever you are moving towards, for example if you are moving towards an object called 'apple' the x co-ordinate would be 'apple.x'

What it does is that if the object is further than 8 pixels away, the object will keep moving towards the target at 4 pixels a step. If it is closer, it stops.

However, the numbers can be different to 8 and 4. Play around a bit and see what works.

P.S. Don't check the relative boxes.

Edited by nukemaster, 05 January 2011 - 03:30 PM.

  • 0

#11 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 06 January 2011 - 05:19 PM

How do we move the object when (the code).
  • 0

#12 Herū

Herū

    GMC Member

  • New Member
  • 37 posts

Posted 05 April 2011 - 03:05 PM

How can I get coordinates to where the user clicked into the "point_distance ()" (from what I know, kn where for some strange reason you do not create your own variables)?
  • 0

#13 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 05 April 2011 - 06:26 PM

How can I get coordinates to where the user clicked into the "point_distance ()"

When you "click" the mouse you copy (in the "mouse" -> "global mouse" -> "global left button" or "global left pressed" event) the "mouse_x" and the "mouse_y" contents into two instance-local variables, and use those two variables in the "point_distance(...)" and "move_towards_point(...)" commands.

I would suggest you use the "xstart" and "ystart" variables, as hey are already present in the instance.

Hope that clarifies it /helps.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users