Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jan 24, 2015 at 02:58 AM by Ujean917 for the following reason:

Found a work around to my issue.

avatar image
0
Question by Ujean917 · Jan 19, 2015 at 07:20 PM · movementcolliderscriptingbasics

How to move a Collider in a Game Object in a Direction

Hello I wanted to know if it was possible to move a collider that's in a game object a certain direction. In this case up and then come back down. This is to make up for the animation I have made for a character that has a jumping animation and it never crossed my mind that the collision would stay the same place making avoiding things with jump pointless. I tried doing a getcomponent and sendmessageupwards command but I couldn't figure out the proper way to do it. If I could get some adive or help that would be amazing.

alt text

Here is the code and script I intend on implementing in:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour 
 {
 
     public float movementSpeed = 10.0f;
     public float angleChangeSpeed = 100.0f;
 
     public bool isDead = false;
     
     private float minX = -15.0f;
     private float maxX = 15.0f;
     private float minZ = 0.0f;
     private float maxZ = 20.0f;
 
     // Update is called once per frame
     void Update () 
     {
         if(!isDead)
         {
             transform.localPosition = new Vector3(Mathf.Clamp(transform.localPosition.x, minX, maxX), 0, 
                                              Mathf.Clamp(transform.localPosition.z, minZ, maxZ));
             // new code
             float horizontal = Input.GetAxis ("Horizontal");
             float vertical = Input.GetAxis ("Vertical");
 
             Vector3 direction = new Vector3 (horizontal, 0, vertical);
             Vector3 finalDirection = new Vector3 (horizontal, 0, 1.0f);
 
 
             transform.position += direction * movementSpeed * Time.deltaTime;
 
             transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation (finalDirection), Mathf.Deg2Rad*angleChangeSpeed);
         }
 
         if (!isDead) 
         {
             if (Input.GetButton ("Jump"))
             {
                 //////////////RIGHT HERE////////////////////////////////////
             }
         }
     }
 
     void SetDead(bool dead)
     {
         Debug.Log ("SetDead was reached");
         isDead = dead;
     }
 }

capsulecollider.png (56.7 kB)
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by danielmetlitski · Jan 21, 2015 at 08:37 AM

this.collider.transform.Translate(Vector3.down* Time.deltaTime * 5);

should work.

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 Ujean917 · Jan 21, 2015 at 05:49 PM 0
Share

Thanks for the reply , but from the code you have provided me is giving me weird error messages that says Time.deltaTime of Vector3.down Time.deltaTime 5 is the cause of it. $$anonymous$$aybe its a syntax error, I'll try with the catalog(or whatever it's called) related to Time.deltaTime on the mean time. I really want to fix this something so small but game breaking.

avatar image Ujean917 · Jan 21, 2015 at 11:56 PM 0
Share

Okay I tried one more attempt in fixing this but I am getting nothing this is $$anonymous$$d boggling. I even checked it here link text but I am not getting anything. If someone can also suggest another way of doing this please do.

avatar image danielmetlitski · Jan 23, 2015 at 09:27 PM 0
Share

for some reason it doesnt show up on my answer, you multiply Vector3.down by Time.deltaTime by 5

this.collider.transform.Translate(Vector3.down times Time.deltaTime times 5);

the star thing does show up for some fing reason on my answers *

avatar image Ujean917 · Jan 24, 2015 at 02:58 AM 0
Share

Thank you for trying to help me but I've found a work around that works just as fine. This wasn't meant to be a realistic game for me to create anyways. So thank you again I'll be closing this now.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

player collite with object and start moonwalking 1 Answer

Can I use transorm.position here? 1 Answer

Weird shaky player behavior (moving through colliders) 0 Answers

Movement Collisions for Flat NPC with Character Controller 0 Answers

IsKinematic player completely frozen 1 Answer


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