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 Posnik · Dec 11, 2012 at 04:35 AM · cameramovementcharactercontrollerspaceship

My character controller and vehicle (spaceship) move at same time

Hi,

I have a FPS game, that includes a FPS Ctrl and a Spaceship.

My problem is that the character and the ship move together on the scene, and I need the FPS ctrl to be able to enter the Spaceship so it can be controlled. Also, this script is best put into the FPS ctrl or the Spaceship? I'm using I'm sorry if this is some repost, but I haven't found something similar that helped. Here's the code I have on the Spaceship so far...

I'm very noob with coding yet...

thanks btw.

 var camera1 : Camera;
 var camera2 : Camera;
 var turnspeed = 5.0;
 var speed = 5.0;
 private var trueSpeed = 0.0;
 var strafeSpeed = 5.0;
 
 var InShip : Transform; 
 var Player : Transform;
 var PlayerIn = false;
 var ExitPoint = Transform;
 var CanChange = true;
 
 function Update () {
 
     var roll = Input.GetAxis("Roll");
     var pitch = Input.GetAxis("Pitch");
     var yaw = Input.GetAxis("Yaw");
     var strafe = Vector3(Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime, Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime, 0);
     var power = Input.GetAxis("Power");
 
     Player = GameObject.FindWithTag("Player").transform;
 
     if(PlayerIn == true)
     {
         Player.transform.position.y  = InShip.transform.position.y;
         Player.transform.position.z  = InShip.transform.position.z;
         Player.transform.position.x  = InShip.transform.position.x;
     }
     else
     {
 
     }
     if(Input.GetKey(KeyCode.W)&& PlayerIn == true)
     {
         rigidbody.velocity = transform.forward * speed *Input.GetAxis("car");
         rigidbody.velocity.y = Input.GetAxis("root");
     }
     //Truespeed controls
 
     if (trueSpeed < 3000 && trueSpeed > -3000)
     {
         trueSpeed += power;
     }
         if (trueSpeed > 3000)
         {
             trueSpeed = 0;  
         }
         if (trueSpeed < -3000)
         {
             trueSpeed = 0;  
         }
         if (Input.GetKey("c"))
         {
             trueSpeed = 0;
             currentVelocity = rigidbody.velocity;
             oppositeForce = -currentVelocity;
             rigidbody.AddRelativeForce(oppositeForce.x, oppositeForce.y, oppositeForce.z);
             print(trueSpeed);
         }
 
         rigidbody.AddRelativeTorque(pitch*turnspeed*Time.deltaTime, yaw*turnspeed*Time.deltaTime, roll*turnspeed*Time.deltaTime);
         rigidbody.AddRelativeForce(0,0,trueSpeed*speed*Time.deltaTime);
         rigidbody.AddRelativeForce(strafe);
     }
 function OnTriggerEnter(other : Collider)
 {
    if(GameObject.FindWithTag("Player")) && (GameObject.FindWithTag ==("Spaceship")
    {
       camera1.enabled = false;
       camera2.enabled = true;
 
    }
 }
Comment
Add comment · Show 1
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 AlucardJay · Dec 11, 2012 at 06:49 AM 0
Share

It may be better to have the 2 control types separated, and decide which to use by a simple boolean switch :

    var isFPS : boolean &#61; true;

when you enter/exit the spaceship, toggle the boolean true/false. YOu probably want to switch cameras here too.

  switch( isFPS )
  {
     case true :
        // do FPS control stuff here
     break;
     
     case false:
        // do Spaceship control stuff here
     break;
  }

when you have separated the controls, it is easier to manage what happens when walking around and what happens when piloting.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by daverocks2 · Dec 11, 2012 at 07:28 AM

You could try

var isPlayerVisible : boolean;

If (input.getAxis("Horizontal") && isPlayerVisible)

Just replace the PlayerIn var with isPlayerVisible

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

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

How do I make my character lean to the sides? 0 Answers

Character movement relative to the camera 1 Answer

change move controls relative to player 1 Answer

character turning where he looks 0 Answers

UNITY 3D: How to make the camera follow the player? Smoothly 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