playMaker

Author Topic: How to check if object is moving on XY axis? (Solved)  (Read 1858 times)

RC

  • Full Member
  • ***
  • Posts: 148
How to check if object is moving on XY axis? (Solved)
« on: September 28, 2014, 07:24:39 PM »
Hi,

I've been struggling on how to get this right.
How do you check if an object is moving  up or down the y axis?

Thank you.
« Last Edit: September 29, 2014, 09:43:58 AM by rongconcrx »

RC

  • Full Member
  • ***
  • Posts: 148
Re: How to check if object is moving on XY axis?
« Reply #1 on: September 29, 2014, 12:05:50 AM »
Bump.
How could I put this into playmaker action?
thanks


Quote
    var old_pos : float;
    function Start(){
    old_pos = transform.position.x;
    }
    function Update(){
    if(old_pos < transform.position.x){
    print("moving right");
    }
    if(old_pos > transform.position.x){
    print("moving left");
    }
    old_pos = transform.position.x;
    }


Quote
    var previous_position = transform.position.z;
    var current_position = transform.positon.z;
    //or whatever axis you're platforming along
     
    function Update()
    {
    if(previous_position > current_position)
    {
    //do whatever you do when you move left
    }
    if(previous positoin < current_position)
    {
    //move right stuff
    }
    previous_position = current_position;
    current_position = transform.position.z;
    }
    // party time!

RC

  • Full Member
  • ***
  • Posts: 148
Re: How to check if object is moving on XY axis?
« Reply #2 on: September 29, 2014, 09:43:04 AM »
Figured it out.