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 Disthron · Apr 19, 2018 at 11:14 AM · collisionrigidbodyvector3.movetowards

How can I make a block push the player?

Hi, I want to make a block that can push the player off of a ledge. I have already made the block move using the Vector3.MoveTowards function and it seems to move basic rigid body cubes normally but when it comes to the character controller it just phases right through. Here is the code I'm working with.

Any help would be apreshiated.

 void Update()
 {
         buttonPressedState = myButton.GetComponent<ButtonBehaviour>().isPressed;
         if (isPositionSwap)
         {
             if (buttonPressedState == swapStateGoal)
             { //if the button is pressed, start the move and swap the desired button output
                 isMoving = true;
                 if (swapStateGoal)
                 {
                     swapStateGoal = false;
                 }
                 else
                 {
                     swapStateGoal = true;
                 }
             }
 
 
             if (isMoving)
             {
                 if (Vector3.Distance(transform.position, targetPosition[currentTargetPosArrIndex].transform.position) > 0.1)
                 { // if not close enough, move closer
                     platNewPos = Vector3.MoveTowards(transform.position, targetPosition[currentTargetPosArrIndex].transform.position, moveSpeed * Time.deltaTime);
                     platMovement = platNewPos - transform.position;
                     transform.position = platNewPos;
                 }
                 else
                 {
                     // close enough swap target position
                     currentTargetPosArrIndex++;
                     if (currentTargetPosArrIndex > targetPosition.Length -1)
                     {
                         currentTargetPosArrIndex = 0;
                     }
                     isMoving = false;
                 }
 
             }
             
         }
         else
         {
             if (buttonPressedState) // when button is pressed
             {
                 if (Vector3.Distance(transform.position, targetPosition[currentTargetPosArrIndex].transform.position) > 0.1)
                 { // if not close enough, move closer
                     platNewPos = Vector3.MoveTowards(transform.position, targetPosition[currentTargetPosArrIndex].transform.position, moveSpeed * Time.deltaTime);
                     platMovement = platNewPos - transform.position;
                     transform.position = platNewPos;
                     
                 }
                 else
                 {
                     // close enough swap target position
                     currentTargetPosArrIndex++;
                     if (currentTargetPosArrIndex > targetPosition.Length -1)
                     {
                         currentTargetPosArrIndex = 0;
                     }
                 }
             }
         }
  }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vollmondum · Apr 19, 2018 at 11:40 AM

Move towards ignores colliders. 1. Player needs to have a rigidbody 2. Player's (or cube's) collider should be thick enough for the cube to react on collision, until its center crossed player's

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
avatar image
0

Answer by Disthron · Apr 19, 2018 at 11:48 AM

Thanks for your response!

Move towards ignores colliders Hmm... what about Lerp, does that ignore colliders too. Also, whey does it work for the basic block but not the player controller.

Comment
Add comment · Show 2 · 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 Vollmondum · Apr 19, 2018 at 11:58 AM 0
Share

There's number of ways to achieve the goal. $$anonymous$$ost people would suggest AddForce to any collidable thingies. I personally prefer $$anonymous$$oveTowards and increase collider's diameter while moving, it moves smoother that way. Lerp is great for camera movement only, considering Lerping something barely reaches final destination coordinate, say while lerping to 1.0, it comes as close as 0.999999, but still not 1, and that's when you don't see a reason for things not to work, since 0.999999 != 1 :)

avatar image Vollmondum · Apr 19, 2018 at 12:52 PM 0
Share

Player Controller is basic thing with its own mechanics and completed scripting. I call it "lazy controller". Drag into the scene and no need for coding. Can't answer about native player controller for sure. I code controllers from scratch

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

141 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

Related Questions

How I can make gameobject detect collisions and make every other gameobject be able to go through it? 1 Answer

Collision without movement!?? 2 Answers

How can the player position updates randomly when the player isn't movingl? 0 Answers

OnCollisionEnter doesn't work if enemies and allies have rigidbody ? 1 Answer

Rigidbody: how to get collisions for the current frame ? 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