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 Sanyazin · Jun 16, 2016 at 11:13 AM · c#collision

My main character isn't being able to colide with the objects.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float movespeed;
     public float jumpheight;
 
     public Transform Groundcheck;
     public float GroundcheckRadius;
     public LayerMask WhatIsGround;
     private bool grounded;
 
     private bool doubleJump;
 
     private Animator anim;
 
     // Use this for initialization
     void Start() {
         anim = GetComponent<Animator>();
     }
 
     void FixedUpdate()
     {
         grounded = Physics2D.OverlapCircle(Groundcheck.position, GroundcheckRadius, WhatIsGround);
     }
 
     // Update is called once per frame
     void Update() {
 
         if (grounded)
             doubleJump = false;
 
         if (Input.GetKeyDown(KeyCode.W) && grounded)
         {
             //GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpheight);
             salto();
         }
 
         if (Input.GetKeyDown(KeyCode.W) && !doubleJump && !grounded)
         {
             //GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpheight);
             salto();
             doubleJump = true;
         }
 
         if (Input.GetKey(KeyCode.D))
         {
             GetComponent<Rigidbody2D>().velocity = new Vector2(movespeed, GetComponent<Rigidbody2D>().velocity.y);
         }
 
         if (Input.GetKey(KeyCode.A))
         {
             GetComponent<Rigidbody2D>().velocity = new Vector2(-movespeed, GetComponent<Rigidbody2D>().velocity.y);
         }
 
         anim.SetFloat("Speed",Mathf.Abs (GetComponent < Rigidbody2D>().velocity.x));
 
     }
 
     public void salto()
         {
       GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpheight);
         }
 }
 

So this is main character code. I will show aswell the Script that i use to when i collide with spikes he dies.

 using UnityEngine;
 using System.Collections;
 
 public class KillPlayer : MonoBehaviour
 {
 
     public LevelManager levelManager;
 
     // Use this for initialization
     void Start()
     {
 
         levelManager = FindObjectOfType<LevelManager>();
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.name == "Kappa kek")
         {
             levelManager.RespawnPlayer();
         }
     }
 }



This was all working until i tried to place the respawn particles and death particles working out. Since i placed this code the Colision isn't working, the Player passes right in the middle of the object nothing happens. And before i placed this code with the particles everything was fine...

 using UnityEngine;
 using System.Collections;
 
 public class LevelManager : MonoBehaviour
 {
 
     public GameObject currentCheckpoint;
 
     private PlayerController player;
 
     public GameObject deathParticle;
     public GameObject respawnParticle;
 
     public float respawnDelay;
 
     // Use this for initialization
     void Start()
     {
         player = FindObjectOfType<PlayerController>();
     }
 
     // Update is called once per frame
     void Update(){
 
     }
 
     public IEnumerator RespawnPlayer()
     {
         Instantiate(deathParticle, player.transform.position, player.transform.rotation);
         player.enabled = false;
         player.GetComponent<Renderer>().enabled = false;
         Debug.Log("Player Respawn");
         yield return new WaitForSeconds(respawnDelay);
         player.transform.position = currentCheckpoint.transform.position;
         player.enabled = true;
         player.GetComponent<Renderer>().enabled = true;
         Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
     }
 
     public void RespawnPlayerCo()
     {
         StartCoroutine("RespawnPlayerCo");
     }
 }

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 Sanyazin · Jun 16, 2016 at 04:20 PM 0
Share

i was able to fix the error deleting IEnumerator and placing a void.

i also deleted yield return new WaitForSeconds(respawnDelay)

and i added a Debug.Log in the $$anonymous$$illplayer Class

Just in case someone has the same problem. Don't use IEnumerator if you are not in loop.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sanyazin · Jun 16, 2016 at 01:28 PM

Back to top.

BUMP

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

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

Particle Collision between particles 0 Answers

Checking for a gameobject at a position 1 Answer

MOBA: Pathfinding and Killing creeps 0 Answers

Audio Timing sync with Collision Object Appearance 0 Answers

Best practive when removing pickup gameObject and its instances 0 Answers


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