Jump to content
Sign in to follow this  
darthbirdy3

Player turn toward where Mouse clicks

Recommended Posts

I have another mouse script that is doing what I want it to and is all set, but what I also wish it could do is make the player turn toward where you clicked. Can somebody write a short separate script that does that?

Share this post


Link to post
Share on other sites

It should be doable,can you link the mouse script you are now using

Share this post


Link to post
Share on other sites

Ok try this script ,it should work fine but tell me if you have any issue

 
class Game_Player < Game_Character

#--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    last_real_x = @real_x
    last_real_y = @real_y
    last_moving = moving?
    move_by_input
    mouse_direction
    super
    update_scroll(last_real_x, last_real_y)
    update_vehicle
    update_nonmoving(last_moving) unless moving?
    @followers.update
  end
  
  
  def mouse_direction
    if Keyboard.trigger?(Keys::M_LEFT)
      mouse_x=Mouse::mouse_coords[0]
      mouse_y=Mouse::mouse_coords[1]
      if (@x*32-mouse_x).abs>(@y*32-mouse_y).abs
        if @x*32-mouse_x>0
          direction=4
        else 
          direction=6
        end
      else 
        if @y*32-mouse_y>0
          direction=8
        else 
          direction=2
        end
      end
      set_direction(direction)
      
    end
    
  end
  
end

Put it below your other scripts (but still above main)

Edited by Shiggy

Share this post


Link to post
Share on other sites

Is there a way to turn it off so you can't turn in a cutscene?

 

EDIT: And thank you so much by the way. I should say that first.

Edited by darthbirdy3
  • Like 1

Share this post


Link to post
Share on other sites

Try to replace this line 

if Keyboard.trigger?(Keys::M_LEFT)

with this

if Keyboard.trigger?(Keys::M_LEFT) && $game_map.interpreter.running?

Share this post


Link to post
Share on other sites

Now it seems not to work at all, but I'm just being picky. Thank you so much for the help and I will live with it. You have earned yourself a spot in the credits :)

Share this post


Link to post
Share on other sites

It's a typo sry :

 

if Keyboard.trigger?(Keys::M_LEFT) && !$game_map.interpreter.running?

 

I forgot the exclamation point

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted