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 /
avatar image
0
Question by mechanicarts · Feb 05, 2013 at 01:15 PM · rotationcollisionrotation axis

transform.forward does not work with Rotate(Vector3.up)

So I'm trying to make a character move based on collisions. When the avatar's hand collides with a "rotator" cube, start rotating to the side of the cube (left/right). However, I also have 2 extra cubes, for movement (forward, backward). These cubes always move on the Vector3.forward axis, although I have explicitly asked for the transform.forward. Check my script and my screenshot. The scripts are as follows.

Screenshot


Collcomp.js

 var TOP:GameObject;
 var RIGHT:GameObject;
 var BOT:GameObject;
 var LEFT:GameObject;
 
 //this is the direction variable. Starting from Top (or front) with 1, counting 1 by 1 moving clockwise.
 
 static var dirVar:int;
 
 function OnTriggerEnter(coll:Collider)
 {
     
     if (coll.gameObject==TOP.gameObject)
     {
         //Debug.Log("Top");
         dirVar=1;
     }
     
     if (coll.gameObject==RIGHT.gameObject)
     {
         //Debug.Log("Right");
         dirVar=2;
     }
     if (coll.gameObject==BOT.gameObject)
     {
         //Debug.Log("Bottom");
         dirVar=3;
     }
     if (coll.gameObject==LEFT.gameObject)
     {
         //Debug.Log("Left");
         dirVar=4;
     }
 
 
 }
 
 function OnTriggerExit(coll:Collider)
 {
     //Debug.Log("Null movement.");
     if (dirVar!=0)
     {
         dirVar=0;
     }
     
 }



MovementScript.js

 var direction:Vector3 = Vector3.zero;
 var character:CharacterController;
 private var front:Vector3;
 private var back:Vector3;
 private var right:Vector3;
 private var left:Vector3;
 
 function Start()
 {
     character = this.GetComponent(CharacterController);
     front = transform.forward;
     back = -transform.forward;
     left = -transform.right;
     right = transform.right;
 
 }
 
 function Update()
 {
     switch(CollComp.dirVar)
     {
         case(1):
         direction = front;
         break;
         
         case(2):
         direction = left;
         break;
         
         case(3):
         direction = back;
         break;
         
         case (4):
         direction = right;
         break;
         
         default:
         direction = Vector3.zero;
         break;
 
     }
     character.Move(direction * speed * Time.deltaTime);
 }

Comment
Add comment · Show 5
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 Graham-Dunnett ♦♦ · Feb 05, 2013 at 09:23 PM 0
Share

Is direction a vector or a float? You use it in the $$anonymous$$ove() so I assume it's a vector. But then you set it to +/-1, which makes it look like a float.

avatar image GC1983 · Feb 05, 2013 at 09:58 PM 0
Share

You can simply rotate the rotate the object with transform.Rotate(x, y, z, Space.Self). Adjust the positive or negative number to whatever axis you want to turn left or right.

You dont need the turn, direction, or Time.deltaTime to make this work.

avatar image mechanicarts · Feb 05, 2013 at 11:20 PM 0
Share

Direction is a V3. I thought that v3 = X is the same as v3(X,X,X). It works anyway so I was never proven wrong.

Also I want the turn because it will be adjustable from the insp, I need direction because I want Debug.Logs also at another point and I read you should use time.deltatime to time stuff correctly.

avatar image Bunny83 · Feb 05, 2013 at 11:54 PM 0
Share

Umm, no, it's not the same. There is no implicit cast from int or float to Vector3. Do you have #pragma strict at the top of your script? If you have you should get a compiler error that you can't convert an int to Vector3.

You said it's a Vector3 but it looks like it's a float since in all places you use it like a float. For example in your Rotate function in line 30 you multiply direction with another Vector3. If directio is also a Vector3 that wouldn't work at all.

The next strange thing is, why do you store the initial forward vector in "front" / "back"? Where do you actually use them? $$anonymous$$eep in $$anonymous$$d that the value that is stored in front / back won't change, it's a value type.

Your whole post is a bit strange. You include stuff you don't use and you omit stuff you actually use. Also it seems that you're not sure what type they have, so i would suggest to rethink the whole thing. Can you explain what it is supposed to do?

avatar image mechanicarts · Feb 06, 2013 at 03:07 AM 0
Share

What it is supposed to do, is when your hand (the avatar is controlled by kinect) collides with a rotator, the rotator sets the direction to positive/negative (actually direction DOES seem wrong as a v3). Then at the Update, based on the direction the collision is giving, rotate the character controller left/right based on direction.

I know the script has some errors. I learnt UnityScript on my own(basics only) and I'm just now taking the Unity course at my Uni. Should I remove the decls for front/back etc?

EDIT: This whole thing is messed up. I'll post the whole scripts separately in my question.

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

12 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

Related Questions

Rigidbody Turning 2 Answers

Player rotating after wall collision 1 Answer

Questions about rotation. 1 Answer

Recreating the rotation sphere in-game? 0 Answers

How can I make player rotation control camera's x rotation and mouse control it's y rotation? 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