Jump to content


Photo

move_towards_point(problem)


  • Please log in to reply
4 replies to this topic

#1 ohaithar

ohaithar

    GMC Member

  • New Member
  • 150 posts
  • Version:GM8

Posted 25 March 2012 - 12:24 PM

Hey, how do i make an object(obj_rocket) move towards any object let's say obj_wall and then spawn something?
When my rocket reaches it's destination it just gets stuck and does nothing.
Another question how do i make my obj_rocket shoot towards obj_player but without following him, just to his direction.


Currently this is what i have :

Step event
move_towards_point(obj_wall.x,obj_wall.y,5)

Collision event
instance_create(obj_rocket.x,obj_rocket.y+40,obj_shoot)
instance_create(obj_rocket.x,obj_rocket.y+40,obj_shoot2)
instance_destroy()

Edited by ohaithar, 25 March 2012 - 12:24 PM.

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 25 March 2012 - 12:44 PM

Okay, for your first problem, you need to do a distance check between your moving object and the point it has to reach :

//STEP EVENT
if point_distance(x, y, obj_Wall.x, obj_Wall.y) > speed
{
move_towards_point(obj_Wall.x, obj_Wall.y, 5);
}
else
{
//SPAWN SOMETHING!
}



Now, for your other question, you need to tell your rocket when it is created what direction to go in :

//EVENT THAT CREATES THE ROCKET
with (instance_create(x, y, obj_Rocket)) direction = point_direction(x, y, obj_Player.x, obj_Player.y);


The "with()" function is very useful and is a great way of telling instances to run some code from inside another instance.

Edited by Nocturne, 25 March 2012 - 02:30 PM.
Minor typo...

  • 1

#3 ohaithar

ohaithar

    GMC Member

  • New Member
  • 150 posts
  • Version:GM8

Posted 25 March 2012 - 01:25 PM

Can't even make the first thing to work, my rocket just stays in 1 place.
More explanation please? What my speed should be? because i wasn't using speed, i was using vspeed for my rocket to go down.

EDIT : I just copied without looking, had to change < to > in step event

Edited by ohaithar, 25 March 2012 - 01:46 PM.

  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 25 March 2012 - 02:29 PM

Oops sorry... Hope itīs working now though!
  • 0

#5 ohaithar

ohaithar

    GMC Member

  • New Member
  • 150 posts
  • Version:GM8

Posted 25 March 2012 - 03:29 PM

Oops sorry... Hope itīs working now though!


Yep, thanks ;]
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users