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 Wintergrasped · Apr 06, 2014 at 05:22 AM · controllerhover

Hover Car Controller?

Ok I got my hover script working and my hover car hovers although I have yet to learn how to make a controller for the car Simply

Move Forward Relatitve to the camera attached to the car. Rotate left or right upon turning. and move backwards relative to the attached camera

I have tryed attaching the first / third person controlser to it and disableing / enabling them when you get in /out o the car i have attempted to use

 using UnityEngine;
 using System.Collections;
 
 public class ControllableSphereComponent : MonoBehaviour
 {
     public float speed= 30;
     public float Force;
     void FixedUpdate()
     {
         if (Input.GetKey("down"))
         {
             this.rigidbody.AddForce(-Time.deltaTime * Force, 0, 0, ForceMode.Acceleration);
         }
         if (Input.GetKey("left")) 
         {
                         transform.Rotate (Vector3.up * speed * Time.deltaTime);
         }    
         if (Input.GetKey("right")) 
         {    
                         transform.Rotate (-Vector3.up * speed * Time.deltaTime);
         }
         if (Input.GetKey("up"))
         {
             this.rigidbody.AddForce(Time.deltaTime * Force, 0, 0, ForceMode.Acceleration);
             Debug.Log("pressRegisterd");
         }
         }
     }


The Problem is if I turn and then go forward it dosent move forward is moves what ever way was forward before I turned.

And I haven't successfully got the Vector3 to move the car forward or backwards.

If you attach a script Please either comment it out or explain how the script works i am here to learn not to get free scripts

Also My Script to enter and Exit the car is:

 static var selectedId : int;
 static var speed : int = 5;
 var lookSpeed = 15.0;
 var moveSpeed = 15.0;
 
 var rotationX = 0.0;
 var rotationY = 0.0;
 var movespeed=50;
     var walking : boolean=true;
     var minimumEnterRange : float = 10.0;
     var currentVehicle : GameObject;
     public var rearCamera : Camera ;
     public var driverCamera : Camera ;
     
      function Start(){
     rearCamera.camera.enabled = true;
     driverCamera.camera.enabled = false;
      }
        
     function Update(){
     
    
     
     
     if (Input.GetKey(KeyCode.I))
     {
     rearCamera.camera.enabled = false;
     driverCamera.camera.enabled = true;
     }
      
     else if (Input.GetKey(KeyCode.O))
     {
     driverCamera.camera.enabled = false;
     rearCamera.camera.enabled = true;
     }
         if(Input.GetKeyDown(KeyCode.H)){
             if(walking){
                 // find all the vehicles in the scene
                 var vehicles : GameObject[] = GameObject.FindGameObjectsWithTag ("Vehical");
                 // find the closest vehicle we are looking at
                 for(var vehicle : GameObject in vehicles){
                     if(Vector3.Distance(vehicle.transform.position, transform.position) < minimumEnterRange){
                         var vehicleInCameraSpace = Camera.main.transform.InverseTransformPoint(vehicle.transform.position).normalized;
                         if(Vector3.Dot(Camera.main.transform.forward, vehicleInCameraSpace)>.3){
                             currentVehicle = vehicle;
                             break;
                         }
                     }
                 }
                 // if we can find a vehicle close enough then lets get in it.
                 if(currentVehicle){
                     walking = false;
                                         rearCamera.camera.enabled = false;
                     driverCamera.camera.enabled = true;
                     Camera.main.GetComponent(CharacterController).enabled=false;
                     Camera.main.GetComponent(CharacterMotor).enabled=false;
                     Camera.main.GetComponent(FPSInputController).enabled=false;
                     Camera.main.GetComponent(MouseLook).enabled=false;
                     Camera.main.GetComponent(SmoothFollow).enabled=false;
                     Camera.main.GetComponent(SmoothFollow).target=transform;
                     Camera.main.GetComponent(CharacterMotor).enabled=false;
                     currentVehicle.GetComponent(CharacterController).enabled=true;
                     currentVehicle.GetComponent(CharacterMotor).enabled=true;
                     currentVehicle.GetComponent(FPSInputController).enabled=true;
                     rearCamera.camera.enabled = false;
                     driverCamera.camera.enabled = true;
                 }
             } else {
                 // if we are currently driving then lets get out of the vehicle.
                 walking = true;
                                     rearCamera.camera.enabled = true;
                     driverCamera.camera.enabled = false;
                 Camera.main.GetComponent(CharacterController).enabled=true;
                 Camera.main.GetComponent(CharacterMotor).enabled=true;
                 Camera.main.GetComponent(FPSInputController).enabled=true;
                 Camera.main.GetComponent(MouseLook).enabled=true;
                 Camera.main.GetComponent(SmoothFollow).enabled=false;
                 Camera.main.GetComponent(CharacterController).CanControl.enabled=true;
                 currentVehicle = null;
             
             //car stuff disable
                     currentVehicle.GetComponent(CharacterController).enabled=false;
                     currentVehicle.GetComponent(CharacterMotor).enabled=false;
                     currentVehicle.GetComponent(FPSInputController).enabled=false;
                     rearCamera.camera.enabled = true;
                     driverCamera.camera.enabled = false;
             }
     }
     }

P.S: I know theres other Questions like this but none of them helped me.

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

22 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

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What's the best alternative to Character Controller? 2 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Native visual scripting? 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