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 /
avatar image
0
Question by Moonlads · Sep 16, 2017 at 07:32 AM · collisioncolliderprefabhitcooldown

Collision Not Responding

Hello i am making a C Road Puzzle Game and i have Player Movement Code[C#] here is my code

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Bounce : MonoBehaviour {

 public Swipe swipeControls;

 public GameObject key;

 float lerpTime ;
 float currentLerpTime;
 float perc = 1;

 Vector3 startPos;
 Vector3 endPos;

 bool FirstInput;
 public bool justJump;

 void Update ()
 {
     if(swipeControls.SwipeLeft || swipeControls.SwipeRight || swipeControls.SwipeUp || swipeControls.SwipeDown)
     {
         if(perc == 1)
         {
             lerpTime = 1;
             currentLerpTime = 0;
             FirstInput = true;
             justJump = true;
         }
     }

     startPos = gameObject.transform.position;
     if (swipeControls.SwipeRight && gameObject.transform.position == endPos) 
     {
         endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
     }
     if (swipeControls.SwipeLeft && gameObject.transform.position == endPos)
     {
         endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
     }
     if (swipeControls.SwipeUp && gameObject.transform.position == endPos)
     {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
     }
     if (swipeControls.SwipeDown && gameObject.transform.position == endPos)
     {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
     }

     if (FirstInput == true)
     {
         currentLerpTime += Time.deltaTime * 5;
         perc = currentLerpTime / lerpTime;
         gameObject.transform.position = Vector3.Lerp(startPos, endPos, perc);
     }
     if(perc > 0.8)
     {
         perc = 1;
     }

     if (Mathf.Round(perc) == 1)
     {
         justJump = false;
     }
 }

 void OnTriggerEnter(Collider myTrigger)
 {
     if(myTrigger.gameObject.name == "Enemy")
     {
         key.SetActive(false);
     }
 }

}

The Problem is that my Player cant Collide with other objects it can only collide using Rigid Body which i do not want in my game,Can someone EDIT my code so Character Controller will be needed so it can collide.Please i am no expert by the way this is my 2nd game.

Comment
Add comment · Show 2
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 PizzaPie · Sep 16, 2017 at 08:37 AM 0
Share

You are moving the Object with transform, meaning you kinda teleporting it to new position. That way the physics system does not work thus no collisions happen, think it like you move an object on Editor , you may place it wherever you want regardless colliders, this is pretty much the same.

To solve it either use Physics (Rigidbody) and assosiated functions to move the obj or in the current code apply a check to see if new location is occupied before moving, but still there will be no actual collisions happen that way. Cheers.

avatar image tmalhassan · Sep 16, 2017 at 09:14 AM 0
Share

Does your player move just fine with this code?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hannounq · Sep 16, 2017 at 09:21 AM

did you add a 2D collider in the unity editor? Thats where i usually add my colliders.

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

126 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

Related Questions

Hit detection at angles of enemy character controller? 1 Answer

Is there a way to create an overlap custom-shape? 0 Answers

Multiple colliders on a single character? 1 Answer

Collision Damage, Hit points and Instantiate 1 Answer

Collision massively misplaced 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