- Home /
Click to move disregards collision?
Alright so if i use the following code`
// Click To Move script
// Moves the object towards the mouse position on left mouse click
var smooth:int; // Determines how quickly object moves towards position
private var targetPosition:Vector3;
function Update () {
if(Input.GetKeyDown(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);
}
then my player that was behaving so nicely before just falls through the world. im almost dead positive that it has something to do with this line
transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
again, before i implemented this code the player was not falling through the world, and now it is.
Sorry, im super new to this, this is the code that im using for click to move
#pragma strict
// Click To $$anonymous$$ove script
// $$anonymous$$oves the object towards the mouse position on left mouse click
var smooth:int; // Deter$$anonymous$$es how quickly object moves towards position
private var targetPosition:Vector3;
function Update () {
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0))
{
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);
}
Answer by TSI25 · Sep 22, 2013 at 08:48 PM
resolved my own issue, turns out the player was a child of something that was making it act really funky in relation to the box collider - still not very fluent with these sorts of hierarchy issues >.<
Your answer
Follow this Question
Related Questions
Player glitching through wall when sprinting 1 Answer
2D Movement [HELP!] 0 Answers
Player-movable rigidbodies w/ collision? 2 Answers
My Raycast acts like it's hitting something when it isn't 0 Answers
Random Movement collision bug 3 Answers