GML clicked or not

P

PatatjeFriet

Guest
Hello,
So I am making a RTS game were you have trees you need to cut for wood. The game must have multiple trees because with 1 tree it would be a boring game. Now I have the question how do you check wich tree you clicked. What i have is when clicked on a tree mp_potential_step and then to the tree but with this you can't have it that it will take the tree you clicked what i mean with this is that when there are 2 trees and i click the furthest it will go to the closest or glitch out because there are mutliple trees. So is there something were you will check wich tree object you clicked and it would go to that tree.

I am using gamemaker 8 pro.
Also i am dutch and can't really well explain it in english.
My question in dutch:

Hallo,
Ik ben dus een RTS game aan het maken waarbij bomen zijn om om te kunnen hakken. Nu heb ik het probleem dat als ik 2 bomen neerzet en ik klik erop 1 de worker of glitcht of naar de dichts bij zijnde gaat. Dit wil ik niet want ik wil juist dat hij naar de gene gaat die je aan klikt. ik gebruik in mijn code mp_potential_step want die gebruik ik ook voor alleen het lopen, maar is er een manier om te kunnen checken op welke boom je klikt en dan dat hij daarnaar toe gaat?

-Patatjefriet
 
D

Dave M

Guest
You could create an object that follows the mouse:

Just a quick example,

Obj_Mouse
End Step:

Code:
x=mouse_x
y=mouse_y
Mouse Button:
Code:
var size, object;
size=16
object= obj_tree
if collision_rectangle(x-size,y-size,x+size,y+size,object,1,0) && other.clicked=0
{
other.clicked=1
target = instance_nearest(x,y,object)
/// code here
}
 
Last edited by a moderator:

TheouAegis

Member
if mouse_button_check(mb_left)
target = instance_position(mouse_x, mouse_y, resource_parent)

Now target is the tree to go to.
 
Top