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 /
This question was closed Jul 13, 2018 at 08:57 PM by BluesyPompanno for the following reason:

Other

avatar image
0
Question by BluesyPompanno · Apr 30, 2018 at 12:05 PM · collisioncolliderterraincharactercontrollership

Ship and terrain collision.Need help.

Hello

I am creating a smalll game where you can control ship and a chracter.

My problem is i have created islands using Unity terrain and I want the ship to collide with the terrain (Stop moving when it hits terrain) instead the ship passes right through it.


In my script i move the ship with transform.Translate and I move the player with Character controller.


I have tried to move the ship with rigidbody but then the collisions don't work with the player. I have also tried to move the ship with character controller but than collisions only work on the part of the ship where the character controller reaches with its radius.


Anybody knows how would i create these collisions ?

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
1
Best Answer

Answer by the_genius · Apr 30, 2018 at 12:12 PM

Transform.Translate just changes the transform.position to move an object. This is like 'teleporting' the object every frame so it will 'teleport' through the terrain without the Physics system interacting at all.

I suggest you use a rigidbody and mesh collider. In your scripts use Rigidbody.AddForce rather than Transform.Translate.

Comment
Add comment · Show 1 · 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 BluesyPompanno · May 01, 2018 at 09:36 AM 0
Share

Thank you for your help.I have managed to fix this.

Here is the whole ship script feel free to use it

  public float turningSpeed;
 
     public float maxSpeed;
     public float acceleration;
     float $$anonymous$$Speed = 0f;
     public float speed;
 
     Vector3 movement;
     Rigidbody rgBody;
 
     // Use this for initialization
     void Start ()
     {
         rgBody = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void FixedUpdate ()
     {
         float leftAndRight = Input.GetAxis("Horizontal");
         float forwards = Input.GetAxis("Vertical");
 
         speed += forwards * acceleration * Time.fixedDeltaTime;
 
         if(speed > maxSpeed)
         {
             speed = maxSpeed;
         }else if(speed < $$anonymous$$Speed)
         {
             speed = $$anonymous$$Speed;
         }
 
         $$anonymous$$ove(forwards);
         
         Turning(leftAndRight);
     }
 
     void Turning(float leftAndRight)
     {
         
         float turn = leftAndRight * turningSpeed * Time.fixedDeltaTime;
 
         Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
 
         rgBody.$$anonymous$$oveRotation(rgBody.rotation * turnRotation);
     }
 
     void $$anonymous$$ove(float forwards)
     {
         movement.Set(0f, 0f,forwards);
 
         Vector3 move = transform.forward * forwards * speed * Time.fixedDeltaTime;
 
         rgBody.$$anonymous$$ovePosition(rgBody.position + move);
     }
 }

Follow this Question

Answers Answers and Comments

156 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

Related Questions

Terrain Detail Mesh Collisions 1 Answer

bullet collision with Terrain and Character Collider doesn't work in very fast speed 2 Answers

Collision Problem - Terrain collider remains flat after raising or lowering it 0 Answers

Crawling around the terrain 3 Answers

Character controller falling down 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