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 greatness · Mar 26, 2016 at 09:21 PM · 2d gameplayertutorial

2D Rougelike Tutorial Part 10-Player Does Not Move

I finished the scripting on part 10 of the tutorial. However, when I tested the game in the game view, nobody moves, including the player. I was able to make the player move in part 9. However, I can't make the player move right now.

[CODE]

using UnityEngine; using System.Collections; using System;

public class Enemy : MovingObject { public int playerDamage;

 private Animator animator;
 private Transform target;
 private bool skipMove;

 protected override void Start()
 {
     animator = GetComponent<Animator>();
     target = GameObject.FindGameObjectWithTag("Player").transform;
     base.Start();
 }

 protected override void AttemptMove<T>(int xDir, int yDir)
 {
 
     if (skipMove)
     {
         skipMove = false;
         return;
     }
     base.AttemptMove<T>(xDir, yDir);
     skipMove = true;
 }
 public void MoveEnemy()
 {
     int xDir = 0;
     int yDir = 0;

     if (Mathf.Abs(target.position.x - transform.position.x) < float.Epsilon)
       yDir = target.position.y > transform.position.y ? 1 : -1;
 
     else
         xDir = target.position.x > transform.position.x ? 1 : -1;

     AttemptMove<Player>(xDir, yDir);

 }

 protected override void OnCantMove<T>(T component)
 {
     Player hitPlayer = component as Player;
     hitPlayer.LoseFood(playerDamage);

 }


}[/CODE]

Is the player not supposed to move, or is it just my scripts fault?

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 greatness · Mar 27, 2016 at 05:24 PM

Answer: Attach a 2D Rigidbody component to the Player. Player had a 2D Box Collider but not a 2D Rigidbody.

Comment
Add comment · Show 1 · 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 greatness · Mar 28, 2016 at 03:14 AM 0
Share

This is the player script:

Player [code=CSharp]using UnityEngine; using System.Collections; using System; using UnityEngine.Scene$$anonymous$$anagement;

public class Player : $$anonymous$$ovingObject { public int wallDamage = 1; public int pointsPerFood = 20; public int pointsPerSoda = 10; public float LevelDelay = 1f;

 private Animator animator;
 private int food;

 // Use this for initialization
 protected override void Start () {
     animator = GetComponent<Animator>();
     food = A_Game_$$anonymous$$anager.instance.playerFoodPoints;
     base.Start();
 }
 void Update()
 {
     if (!A_Game_$$anonymous$$anager.instance.playerTurns) return;
     int horizontal = 0;
     int vertical = 0;
     horizontal = (int)(Input.GetAxisRaw("Horizontal"));
     vertical = (int) (Input.GetAxisRaw("Vertical"));
     if (horizontal != 0)
         vertical = 0;
     if (horizontal != 0 || vertical != 0)
         Attempt$$anonymous$$ove<Wall>(horizontal, vertical);
 }

 private void OnDisable()
 {
     A_Game_$$anonymous$$anager.instance.playerFoodPoints = food;
 }

 protected override void Attempt$$anonymous$$ove<T>(int xDir, int yDir)
 {
     food -= 10;
     base.Attempt$$anonymous$$ove<T>(xDir, yDir);
  
     CheckIfGameOver();
     A_Game_$$anonymous$$anager.instance.playerTurns = false;
 }
 private void CheckIfGameOver()
 {
     if (food <= 0)
         A_Game_$$anonymous$$anager.instance.GameOver();
 }

 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Exit"))
     {
         Invoke("Restart", LevelDelay);
         enabled = false;
     }
     if (other.CompareTag("Food"))
     {
         food += pointsPerFood;
        Destroy(other.gameObject);
     }
     else if (other.CompareTag("Soda"))
     {
         food += pointsPerSoda;
         Destroy(other.gameObject);
     }
 }

 // Update is called once per frame

 protected override void OnCant$$anonymous$$ove<T>(T component)
 {
     Wall hitWall = component as Wall;
     hitWall.DamageWall(wallDamage);
     animator.SetTrigger("PlayerChop");
 }
 private void Restart()
 {

     Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex);

 }
 public void LoseFood(int loss)
 {
     animator.SetTrigger("PlayerHit");
     food -= loss;
     CheckIfGameOver();
 }


}[/code]

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

58 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 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

2D Rougelike Tutorial-Part 11 Player Does Not Move 0 Answers

How to make a Inventory Hotbar 0 Answers

UFO Tutorial, after pickup vid, my player ignores the wall collisions 0 Answers

Why won't my player move left? 0 Answers

roll the ball - player not moving. Script seems fine,Roll a ball not rolling, should I add speed ? 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