playMaker

Author Topic: Moving a 2d object in a forward direction  (Read 1805 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Moving a 2d object in a forward direction
« on: October 20, 2019, 01:35:36 PM »
Hi, I've searched this through the forum and can't seem to find the right answer for me.
 
All I need is to point an object at a target (used look At) and need to use set velocity 2d or add relative force 2d, to move the object in its forward direction. And I can't get it to move forward.  I know there must be a simple solution to this... Can someone help?

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Re: Moving a 2d object in a forward direction
« Reply #1 on: October 20, 2019, 08:40:34 PM »
Forward direction? Any other detail? Are you making 8 direction game? Or SideScroll?

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: Moving a 2d object in a forward direction
« Reply #2 on: October 21, 2019, 12:52:40 AM »
Maybe using 'Move Towards' action to move the object into anything it looks at.

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Moving a 2d object in a forward direction
« Reply #3 on: October 21, 2019, 03:43:31 AM »
Forward direction? Any other detail? Are you making 8 direction game? Or SideScroll?

I want it to move in directions to the left and right side, so I have it facing the target, I just need it to move in the facing direction using add force 2d or add velocity 2d.  I can only move in either the x or y, not the facing forward direction.

Maybe using 'Move Towards' action to move the object into anything it looks at.

Yes that works but I need to use physics as the object needs to bounce off of walls etc.

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Re: Moving a 2d object in a forward direction
« Reply #4 on: October 21, 2019, 10:18:35 PM »
If it is only left and right as you said, u can:
1.Get current facing direction of the sprite via scale value
2.Apply positive or negative X direction force base on 1