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 /
  • Help Room /
avatar image
0
Question by Nightm4reProds · Jan 21, 2019 at 01:53 PM · collisionmovementrigidbodycolliderfps

Colliders "offset" and going down too.

alt textWell, Im just trying to create my own FPS Controller for my game to learn and well, you know, knowing what Im using. The thing is that I cant avoid the collider to go into the walls or, for example, if theres an spherical collider in the air, burying itself in the ground. Here's my script and my config. Jugador has rigidbody and box collider, Cube just has collider but even deactivating it still happens the same.

EDIT: You can see in the script that I've tried all the "movement" methods I have found.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class cameraAdmin : MonoBehaviour
 {
 
     public GameObject Target;
     Camera cameraPlayerCam;
 
     private float sensibility = 1.5f;
 
     float v;
     float h;
 
     private float velocidad = 0.01f;
     private float run;
 
     public float fuerzaSalto = 150f;
     public bool isGrounded;
 
     Ray rayAim;
     private Rigidbody selfRigidbody;
     private RaycastHit hit;
 
 
     // Start is called before the first frame update
     void Start()
     {
         if (GameObject.FindGameObjectWithTag("Player"))
         {
             Target = GameObject.FindGameObjectWithTag("Player");
         }
 
         selfRigidbody = Target.GetComponent<Rigidbody>();
 
         cameraPlayerCam = GetComponent<Camera>();
 
         cameraPlayerCam.transform.parent = Target.transform;
     }
 
     // Update is called once per frame
     void Update()
     {
 
         h = sensibility * Input.GetAxis("Mouse X");
         v = sensibility * Input.GetAxis("Mouse Y");
 
         Target.transform.Rotate(0, h, 0);
         cameraPlayerCam.transform.Rotate(-v, 0, 0);
 
         rayAim = cameraPlayerCam.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
 
         cameraPlayerCam.transform.localPosition = new Vector3(0, 0.08f, 0.03f);
 
         
 
 
         /*
         if (Input.GetKey(KeyCode.W))
         {
             Target.transform.Translate(0, 0, velocidad * run);
 
         }
 
         if (Input.GetKey(KeyCode.D))
         {
             Target.transform.Translate(velocidad * run, 0, 0);
 
         }
 
         if (Input.GetKey(KeyCode.A))
         {
             Target.transform.Translate(-velocidad * run, 0, 0);
 
         }
 
         if (Input.GetKey(KeyCode.S))
         {
             Target.transform.Translate(0, 0, -velocidad * run);
 
         }
         */
 
         if (Input.GetKey(KeyCode.LeftShift))
         {
             run = 2f;
         }
         else
         {
             run = 1f;
         }
 
         if (Input.GetKey(KeyCode.V))
         {
 
             if (GameObject.FindGameObjectWithTag("Player") && !Target.CompareTag("Player"))
             {
                 Target = GameObject.FindGameObjectWithTag("Player");
                 cameraPlayerCam.transform.parent = Target.transform;
                 cameraPlayerCam.transform.rotation = Target.transform.rotation;
                 selfRigidbody = Target.GetComponent<Rigidbody>();
             }
 
         }
 
 
 
         if ((Input.GetKeyDown(KeyCode.Space)) && (isGrounded))
         {
             selfRigidbody.AddForce(0, fuerzaSalto, 0);
         }
 
         if (Input.GetKeyDown(KeyCode.F))
         {
             if (Physics.Raycast(rayAim, out hit, 15f))
             {
                 if (hit.collider.CompareTag("NPC"))
                 {
                     Target = GameObject.Find(hit.collider.name);
                     cameraPlayerCam.transform.parent = Target.transform;
                     cameraPlayerCam.transform.rotation = Target.transform.rotation;
                     selfRigidbody = Target.GetComponent<Rigidbody>();
                 }
             }
         }
     }
 
 
     private void FixedUpdate()
     {
         float x = Input.GetAxisRaw("Horizontal");
         float z = Input.GetAxisRaw("Vertical");
         selfRigidbody.position += z * transform.forward * Time.deltaTime * 1f;
         selfRigidbody.position += x * transform.right * Time.deltaTime * 1f;
         /*
         if (Input.GetKey(KeyCode.W))
         {
             selfRigidbody.MovePosition(transform.position + (transform.forward * Time.deltaTime * velocidad));
 
         }
 
         if (Input.GetKey(KeyCode.D))
         {
             selfRigidbody.MovePosition(new Vector3(velocidad * run, 0, 0));
 
         }
 
         if (Input.GetKey(KeyCode.A))
         {
             selfRigidbody.MovePosition(new Vector3(-velocidad * run, 0, 0));
 
         }
 
         if (Input.GetKey(KeyCode.S))
         {
             selfRigidbody.MovePosition(new Vector3(0, 0, -velocidad * run));
 
         }*/
     }
 }


sharedscreenshot2.jpg (183.7 kB)
Comment
Add comment · Show 2
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 Nightm4reProds · Jan 24, 2019 at 10:20 AM 0
Share

Does anyone know...?

avatar image Nightm4reProds · Jan 28, 2019 at 08:05 AM 0
Share

I thought it was easy to do...

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

306 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 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

Rigidbody going through Colliders help! 1 Answer

Need help with high speed collisions, sanity dwindling 1 Answer

How to make rigidbody not effect movement while still using it for collisions? 0 Answers

Player moving though walls while pressing two keys 0 Answers

Sphere movement with attached cube 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