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 ismaa3d · May 26, 2020 at 04:17 PM · movementplatforms

Parent the player to a moving platform in fixedUpdate

I have a player with a CharacterController. The script that controlls the inputs is called "PlayerController" and the one that controlls the platform "MovingPlatform". When the player collides with the moving platform's parent, that works perfect.

The problem comes when I change the Update method of the "PlayerContoller" for one FixedUpdate the player parents to the platform but doesn't stick to the platform.

This is the PlayerContoller script:

private void FixedUpdate() {

     isGrounded = controller.isGrounded;
    
     InputX = Input.GetAxis("Horizontal");
     InputZ = Input.GetAxis("Vertical");
     Speed = new Vector2(InputX, InputZ).sqrMagnitude;
     var camera = Camera.main;
     var forward = cam.transform.forward;
     var right = cam.transform.right;
     forward.y = 0f;
     right.y = 0f;
     forward.Normalize();
     right.Normalize();
     desiredMoveDirection = forward * InputZ + right * InputX;
     if (!forceField.activeInHierarchy)
     {
         shoulderMovement.enabled = true;
         shotcon.enabled = true;
     }
     if (forceField.activeInHierarchy)
     {
         shoulderMovement.enabled = false;
         shotcon.enabled = false;
     }

     if (groundCheck == true)
     {
         anim.SetBool("isGrounded", true);
     }
     if (groundCheck == false)
     {
         anim.SetBool("isGrounded", false);
     }

     onSlope = OnSlope();

     if (isGrounded)
     {
        
         velocity = 0.0f;
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
         moveDirection = desiredMoveDirection * velocity;
         particula1.SetActive(true);
         particula2.SetActive(true);
         particulaJump.SetActive(true);
         isJumping = false;

         if (Input.GetButtonDown("Jump") && !forceField.activeInHierarchy)
         {
             
             MakeJump();
         }
     }
     else
     {
         if (!onSlope)
         {
             velocity = 3f;
             moveDirection.x = desiredMoveDirection.x * velocity;
             moveDirection.z = desiredMoveDirection.z * velocity;
             
         }else if (onSlope)
         {
             isJumping = false;
             if (!isJumping && Input.GetButtonDown("Jump") && !forceField.activeInHierarchy)
             {
                 
                 MakeJump();
             }
         }
        
     }
     moveDirection.y -= gravity * Time.deltaTime;
     controller.Move(moveDirection * Time.deltaTime);
 }

This is the MovingPlatform script:

public class MovingPlatform : MonoBehaviour {

 public Transform [] waypoints;
 private int current = 0;
 private Transform[] inverse;
 public float speed;
 private float WP_radius = .1f;
 public GameObject[] bones;
   

 protected void FixedUpdate()
 {
    
     if(Vector3.Distance(waypoints[current].transform.position, transform.position) < WP_radius)
     {
         current++;
         
         if(current >= waypoints.Length)
         {
             current = 0;
            
         }
         
     }
     transform.position = Vector3.MoveTowards(transform.position, waypoints[current].transform.position, Time.deltaTime * speed);

 }

 private void OnTriggerEnter(Collider other)
 {
     
     if (other.gameObject.tag == "Player")
     {
         other.GetComponent<CharacterController>().Move(Vector3.down *2);
         other.transform.parent = transform;
       
         //desactivar dynamic bone
         foreach (GameObject bone in bones)
         {
             bone.GetComponent<DynamicBone>().enabled = false;
         }
         
     }
 }

 private void OnTriggerExit(Collider other)
 {
     
     if (other.gameObject.tag == "Player")
     {
         other.transform.parent = null;
         
         //activar dynamic bone
         foreach (GameObject bone in bones)
         {
             bone.GetComponent<DynamicBone>().enabled = true;
         }

     }
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

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

Character Diagonal Movement Issue 3 Answers

Copy/ record player movement and apply to AI,How Can i record my movement and apply to AI cars 1 Answer

How to determine if an Enemy is moving left or right? 2 Answers

Switching lanes 1 Answer

Why can't I move my player? 2 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