Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Kappa_1 · Feb 25, 2016 at 12:43 AM · collider2d

my script does not work

I am making my first game it is just pac-man but I cant do the script plz help here is the script using UnityEngine; using System.Collections;

public class PacmanMove : MonoBehaviour { public float speed = 0.4f; Vector2 dest = Vector2.zero;

 void Start() {
     dest = transform.position;
 }

 void FixedUpdate() {
     
     Vector2 p = Vector2.MoveTowards(transform.position, dest, speed);
     GetComponent<Rigidbody2D>().MovePosition(p);
 }

 bool valid(Vector2 dir) {
     
     Vector2 pos = transform.position;
     RaycastHit2D hit = Physics2D.Linecast(pos + dir, pos);
     return (hit.collider == collider2D);
 }

}

void FixedUpdate() { // Move closer to Destination Vector2 p = Vector2.MoveTowards(transform.position, dest, speed); GetComponent().MovePosition(p);

 // Check for Input if not moving
 if ((Vector2)transform.position == dest) {
     if (Input.GetKey(KeyCode.UpArrow) && valid(Vector2.up))
         dest = (Vector2)transform.position + Vector2.up;
     if (Input.GetKey(KeyCode.RightArrow) && valid(Vector2.right))
         dest = (Vector2)transform.position + Vector2.right;
     if (Input.GetKey(KeyCode.DownArrow) && valid(-Vector2.up))
         dest = (Vector2)transform.position - Vector2.up;
     if (Input.GetKey(KeyCode.LeftArrow) && valid(-Vector2.right))
         dest = (Vector2)transform.position - Vector2.right;
 }

 // Animation Parameters
 Vector2 dir = dest - (Vector2)transform.position;
 GetComponent<Animator>().SetFloat("DirX", dir.x);
 GetComponent<Animator>().SetFloat("DirY", dir.y);

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jgodfrey · Feb 25, 2016 at 01:00 AM

Honestly, you're not going to get far in game development without some scripting knowledge. So, you probably either need to put together a team of people with varying talents (coding, artwork, sound design, modeling, etc), or you're going to have to commit to learning enough to do it all yourself.

This place is great when you're having a specific problem, need some advice, or just a push in the right direction. However, it's not a place where you can just drop in and ask for a "pacman script". There's a lot that goes into the development of a complete game - even a relatively simple game like pacman. You can't expect someone else to provide that via a simple forum request.

I suggest you buckle down, take a look at some tutorials, and begin to learn the process. It's not necessarily easy, but it is rewarding.

Good luck.

Comment
Add comment · 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

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

46 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stop ball sprite passes through the wall? 1 Answer

make 2 objects on 2d to collide with each other 0 Answers

How To Smoothly Climb Over Tiles? 1 Answer

Hit from kinematic rigidbody2d 1 Answer

Sprite do not collide with another sprite (Even with collider and Rigidbody) [2D] 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