Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ThePhantomPsychic · Jul 21, 2015 at 03:38 PM · c#aienemy

Enemy/Partner AI without rotation

I have tried a ton of AI scripts around here for my game, and they all have one thing in common. They all rotate the object it's attached to.

I'm trying to make a Paper Mario game, and if anyone has played those games, you know that no-one (ok, one star kid), turns sideways when the camera is facing them.

I need to know how to make a script that follows the player and stops at a distance, and depending if he/she is on the right or left side of mario, their x-axis scale is inverted.

Right now all I'm getting is just a bunch of rotating sprites, and that isn't good for a paper mario game.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Curse_Of_The_No_Map · Jul 23, 2015 at 04:32 AM 0
Share

Have you tried Vector2.$$anonymous$$oveTowards? For the distance between the objects use distance formula. For right or left side check if x pos is greater or less than mario.

avatar image ThePhantomPsychic · Jul 23, 2015 at 01:23 PM 0
Share

$$anonymous$$eep in $$anonymous$$d, I'm using 2d sprites on a 3d surface, so I don't think I can use Vector 2.

avatar image Curse_Of_The_No_Map · Jul 23, 2015 at 04:11 PM 0
Share

So your gameplay is similar to that of castle crashers were you can move front to back and side to side but your character appears 2D?

avatar image ThePhantomPsychic · Jul 23, 2015 at 07:31 PM 0
Share

Yes, but with paper mario.

avatar image ThePhantomPsychic · Jul 23, 2015 at 11:19 PM 0
Share

Yes. That is basically it.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fuego_see_money · Jul 23, 2015 at 09:15 PM

try this, keep in mind I am at work and cannot test anything. let me know if you need help still after this. attach this to your partner. its commented fairly well so I hope you understand it.

 public class Partner : MonoBehaviour
 {
     public GameObject toFollow;//this should be Mario,set in inspector
     public float stoppingRadius = 5f;//however much you want
     public float moveSpeed = 2f;//however much you want
     public float initXScale;
     
     void Start()
     {
         initXScale = this.transform.localScale.x;
     }
     
     void FixedUpdate()
     {
         //get direction towards mario, multiply by your follow speed
         Vector3 dir = toFollow.transform.position - this.transform.position;
         float distance = dir.magnitude;
         dir.Normalize();
         
         //are we far enough away from him?
         if(distance > stoppingRadius)
         {
             //move towards him
             //get move vector
             Vector3 move = dir * moveSpeed;
             
             //I am going to assume you dont want your partner to move on the up axis (float away) so we are going to remove the Y component of move
             move = new Vector3(move.x, 0, move.z);
             //I dont know if youre using a rigidbody...im going to just assume you arent
             this.transform.position += move;
             
             //finally...are we on the left or right of him?
             if(dir.x > 0)
             {
                 this.transform.localScale = new Vector3(initXScale, this.transform.localScale.y, this.transform.localScale.z)
             }
             else
             {
                 this.transform.localScale = new Vector3(-initXScale, this.transform.localScale.y, this.transform.localScale.z)
             }
         }
     }
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThePhantomPsychic · Jul 23, 2015 at 11:31 PM 0
Share

This had one oddball effect. He would always be facing away from me, even when I set it to negative, and wouldn't actually move. He would just start flashing, and once I got to a certain point, he would appear in front of me, still flashing. I wish I could explain it more, but if you get the time, please test it.

avatar image fuego_see_money · Jul 24, 2015 at 05:34 PM 0
Share

Really? Is your game 2-D? What are your global axis?

avatar image fuego_see_money · Jul 24, 2015 at 05:37 PM 0
Share

You are using 2D sprites in a 3D environment, like Paper $$anonymous$$ario, correct?

Also what value were you setting to negative?

avatar image ThePhantomPsychic · Jul 24, 2015 at 09:20 PM 0
Share

Yes, I said that.

I am setting the x-scale to negative, because that's how it is in game for me. When I make sprites (slice or normal) they appear backwards in game, even before your script, so in order to set them right, I reverse the x-scale.

avatar image ThePhantomPsychic · Jul 27, 2015 at 04:55 PM 0
Share

Do you know what's causing the problem?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Send an enemy back to its spawn point using waypoints 2 Answers

My bullet has no velocity after it is spawned. 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Enemy AI C# 0 Answers

Multiple Cars not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges