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 /
This question was closed Apr 11, 2016 at 04:46 AM by Ryanless for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ryanless · Apr 08, 2016 at 11:29 AM · physicsplayergame

Moving Plattform interaction with player

So in my jumping game i want moving plattforms : Now the plattforms work fine on their own, their iteraction with the player is wierd though in 2 situations:

if the player is below the plattform, he doesnt get pushed away/ "crashed". Instead the plattform moves through the player. Adding a rigidbody to the plattform makes it worse, because then the player even starts to push the plattform away instead of the other way around. How can i have the plattform push the player away from beeing underneath?

if the plattform goes in a direction other than the y-axis and the player is ON the plattform. The player isnt moved along with the plattform. So he kind a has to run to stay on the moving plattform. How can i make the player move with the plattform in all 3 axis?

Here the moving plattform code, not sure if it's of any help for answering my question though.

 using UnityEngine;
 using System.Collections;
 
 public class MovingAB : MonoBehaviour {
     
     public float x = 0;
     public float y = 0;
     public float z = 0;
     public float offset = 0;    //percent done going to B
 
     public float speed = 2;
 
     Vector3 PointA;
     Vector3 PointB;
     Vector3 direction;
     float way;
     float wayDone =0;
 
     bool gotoB = true;
 
     // Use this for initialization 
     void Start () {
 
         PointA = transform.position;
         PointB = PointA + new Vector3 (x, y, z);
         direction = (PointB - PointA).normalized;
         way = (PointB - PointA).magnitude;
 
         transform.position += offset *way/100 * direction;
         wayDone += offset* way/100;
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (gotoB) {
             transform.position += direction * speed * Time.deltaTime;
             wayDone += speed * Time.deltaTime;
         } else {
             transform.position -= direction*speed*Time.deltaTime;
             wayDone += speed * Time.deltaTime;
         }
         //check if reached pointA or B and reverses direction
         if (wayDone >= way) {
             gotoB = !gotoB;
             wayDone -= way;
         }
     
     }
 }

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

  • Sort: 
avatar image
1
Best Answer

Answer by Happy-Zomby · Apr 09, 2016 at 07:48 AM

Hi, I would recommend using colliders and functions on triggerStay and on triggerExit

 function OnTriggerStay(other:Collider)
 {
        if(other.gameObject.tag == "platformAbove")
             {
              transform.position += platform.movement; //add the platform movement to your player
              }
 }

Then you could also create a second collider under the platform and ontriggerstay or on triggerenter it would kill or move your player. Hope this helps,

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 Ryanless · Apr 09, 2016 at 10:14 PM

Great, that works. I didnt use tag regonize, that way it moves anything on top of it . For example boxes, or enemies.

Now for the crushing part, the scaling of the transform works nice. There's a litte problem with the collider though:

 // scales the collider if its not a boxcollider
 void scaleCollider(Collider c){
     if (c.GetType () == typeof(SphereCollider) || c.GetType () == typeof(CapsuleCollider)) {
         if (c.radius >= 0.1) {        //yes, i do know that c has a radius!!!
             c.radius -= speed * Time.deltaTime * crushspeedfactor;
         }
     }
 }

It wont accept c.radius. How can have it know that c is not only a collider but spherecollider/capsulecollider?

Comment
Add comment · Show 4 · 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 Happy-Zomby · Apr 10, 2016 at 07:26 AM 0
Share

Hi, if you scale your transform, your collider should scale with it if I'm not mistaken. Is that not the case? (assu$$anonymous$$g collider is on the same gameobject as the transform you are scaling or on a child one). I would just transform.localscale of the main gameobject and make sure you move it down by half the crush factor to prevent it fron taking off from the ground. I think you should also deactivate the collider during the crusing to prevent any issues hope that helps,

avatar image Ryanless Happy-Zomby · Apr 10, 2016 at 01:19 PM 0
Share

it does so for boxcollider and the height of capsulecolliders. Wished it was for all colliders like that. But:

The radius of the spherecollider is just a collider with radius r (=max( x,y,z)). max(x,z) for capsule. And since i just scale them in y-direction (actually i even "flaten" them by increasing x,z size slightly).

Spheres keep their collidersize completly and capsulecollider get resized to radius x-sphere (asu$$anonymous$$g x==z).

avatar image Happy-Zomby Ryanless · Apr 10, 2016 at 03:22 PM 0
Share

And simply deactivating (enabled = false) or destroying it?

Show more comments

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

any tutorial for playercontroll, physics ? 0 Answers

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

Third person game hit a ball 0 Answers

C# Lerping Problem 0 Answers

Player sticking walking around inside tunnel.. Raycast HOW? 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