• 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 Rickasheye · Jun 06, 2016 at 07:09 AM · transform.translatetransform.rotate

Pac-Man Ghost AI

i tried to make a animation for the ghost ai and tried to stop the animation and make it look at the player but i got to stuck but i tried to go with raycasting which ended up with the same result but with errors heres what i had using UnityEngine; using System.Collections; public class ghostAI : MonoBehaviour { %|-1137081967_1|% %|-1863972952_2|% %|1266049162_3|% %|1716386108_4|% %|-415999389_5|% %|149016438_6|% %|-1650711200_7|% %|-235674992_8|% %|-1548164085_9|% %|1802277094_10|% %|1778270671_11|% %|1741920446_12|% %|-4946239_13|% %|-2096908437_14|% } but i got a few errors on line (17, 15, 9) and i cannot resolve it i want the ghost to move but not touch the walls and not get stuck

When a ghost touches a wall it rotates when it does not touch a wall it moves forward but i want a full snaped turn not a 0.1 turn

Comment
Add comment · Show 1
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 Rickasheye · Jun 05, 2016 at 06:14 AM 0
Share

sorry about the code heres it here in text form using UnityEngine; using System.Collections;

public class ghostAI : $$anonymous$$onoBehaviour {

 public int speed;
 void Update(){
     RaycastHit hit;
     Ray ray = Vector3.forward;
     if (Physics.Raycast (ray, out hit)) {
         if (hit.collider != null) {
             transform.Rotate (transform.forward * speed * Time.deltaTime);
         }

         if (Physics.Raycast(transform.position, ray, 10) == null) {
             print ("Empty Spot $$anonymous$$oving Forward");
             transform.translate (transform.forward * Time.deltaTime * speed);
         }
     }
 }

}

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Rotate/Translate a GameObject via C# Script 3 Answers

Use Bounciness with Object.Transform 0 Answers

Turn page, smooth rotate 1 Answer

How to transform.Rotate a second camera? 1 Answer

Relative rotation with touch sometimes jumps to new rotation 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges