hello whats wrong with my player collision i have a script on it to move and character controller to collide and doesnt colide note: tried box collider , with triggers and without triggers any idea why doesnt colide?
So, you have a character controller as the player. right? Also you have the object(s) you want to collide with and in these object(s) you have a box collider and these/this box collider is not a trigger? If all is correct it should work correctly...
What are you using to move the character? Transform.position = something? Transform.Translate? CharacterController.Move?
what doesn't work? You know nobody is going to be able to help you unless you speak up a bit and by speaking up a bit I mean like, Posting your code and explaining a little bit more about what's going on..
Okay i will explain everything first im gonna make a game with ships and sea etc.. i added the player now a cube added ground positioned everything 0,0,0 lowered the ground(cube) to be lower than the player added this script to the player to move : Code (csharp): var smooth:float; private var targetPosition:Vector3; function Update () { if(Input.GetKey(KeyCode.Mouse0)) { var playerPlane = new Plane(Vector3.up, transform.position); var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hitdist = 0.0; if (playerPlane.Raycast (ray, hitdist)) { var targetPoint = ray.GetPoint(hitdist); targetPosition = ray.GetPoint(hitdist); var targetRotation = Quaternion.LookRotation(targetPoint - transform.position); transform.rotation = targetRotation; } } transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth); } added character controller to the player made the radius to be equals to the cube added box collider to the wall (to test if it collides) doesnt collide and if i add rigidbody to the wall or the player acts werry stupid
So the code you gave us was the player code? If so it most likely won't work with a characterController.
try working with this Code (csharp): /// This script moves the character controller forward /// and sideways based on the arrow keys. /// It also jumps when pressing space. /// Make sure to attach a character controller to the same game object. /// It is recommended that you make only one call to Move or SimpleMove per frame. var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0; private var moveDirection : Vector3 = Vector3.zero; function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller controller.Move(moveDirection * Time.deltaTime); }
works but its totaly diferent works with arrows can jump i can disable that and acts weird idk is there some way i can do that without applying gravity cuz its ship... and doesnt act like a ship totaly doesnt
if you don't want gravity and jumping here it is: Code (csharp): var speed : float = 6.0; private var moveDirection : Vector3 = Vector3.zero; function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; } // Move the controller controller.Move(moveDirection * Time.deltaTime); } this is untested code, but it should work...
since your object doesn't jump, you do not need to check if it's grounded, place a character controller on the playercube, put this code on it, make sure everything that has a collider on it, has the is Trigger option disabled. Code (csharp): var speed : float = 6.0; var moveDirection : Vector3 = Vector3.zero; function Update() { var controller : CharacterController = GetComponent(CharacterController); moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; controller.Move(moveDirection * Time.deltaTime); }
you need to create a waypoint system, spawn a waypoint at the mouse coordinates (create a ray that intersects your plane and get the coords for that point and use instantiate) on the boat check every frame if there is a waypoint on the map, if there is go to it, you can use LookAt (your waypoint) to rotate and move towards it. if another mouseclick event happens you destroy the previous waypoint, and instantiate another one at the location mentioned above.
here's some code to get you started, it spawns waypoints and it makes the character controller look at that specific waypoint. Movement script attached to your boat (character controller): Code (csharp): using UnityEngine; using System.Collections; public class movement : MonoBehaviour { public GameObject boat; public GameObject wp; public float speed; public float distance; public CharacterController controller; // Use this for initialization void Start () { speed = 2.0f; distance = 0.0f; boat = GameObject.FindGameObjectWithTag("Player"); } // Update is called once per frame void Update () { wp = GameObject.FindGameObjectWithTag("Waypoint"); if(wp){ distance = Vector3.Distance(boat.transform.position, wp.transform.position); boat.transform.LookAt(wp.transform.position); Debug.Log(distance); if(distance > 0){ //place your movement script here } } } } and here's the code for spawning waypoints: you attach it to the ground. Code (csharp): #pragma strict public var wp : GameObject; private var position : Vector3; function Update(){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (collider.Raycast (ray, hit, 100.0)) { Debug.DrawLine (ray.origin, hit.point); position = hit.point; position.y = 0; if(Input.GetButtonDown("Fire2")) Instantiate(wp, position, Quaternion.identity); } }
ohh, i forgot about the waypoint code. you must first create a new prefab, place a sphere in it, and remove mesh renderer. make a new tag name it "Waypoint" and tag the new prefab. and tag your boat "Player" here's the waypoint code: Code (csharp): using UnityEngine; using System.Collections; public class waypoint : MonoBehaviour { private GameObject wp ; // Use this for initialization void Start () { wp = GameObject.FindGameObjectWithTag("Waypoint"); } // Update is called once per frame void Update() { if(Input.GetButtonDown("Fire2")) DestroyImmediate(wp); } }