I have a line of code transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
that takes the normal of the raycast hit “hit” and applies the players rotation to it. then i have the code transform.RotateAround(transform.position, transform.up, Input.GetAxis("Mouse X") * sensitivityX);
that rotates the player along the y axis. the problem is, I need to have the player update the normal of the plane they are standing on every frame and make sure they are aligned with it, and make sure they can rotate along the y axis, but the first line of code prevents the second line from even coming into effect. how can I fix this?
No one know how to fix this?
anybody?
Does no one know what I can do to fix this? Its pretty important…
This problem is still unsolved, I would appreciate any assistance
Quaternion.Slerp
and Google it hard. It’s in a lot of tutorials.
Dont really see how thats going to help… maybe a better explanation?
if (Input.GetKeyDown(KeyCode.R)) {
if (gravLock) {
gravLock = false;
}
else if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y - 1, transform.position.z), -transform.up, out hit, gravbootsCastDepth)) {
transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
cam.localEulerAngles = transform.forward;
gravLock = true;
rigidbody.velocity = Vector3.zero;
}
}
this is the code i use to first align the player with the normals of a mesh, (or more specifically the transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal); line) the problem is, they need to stay aligned with the normals underneath them (so the player can walk around spheres and still stay on the sphere), so i solved that problem by casting a ray every frame and then using the same code to keep them aligned with the normals, the problem is, the second line of code from my opening post doesnt have any effect because the other line of code aligns the player with the normals along all axises, restricting all other rotation of the player, even if its just rotating side to side. I need to have the player rotate side to side though, and this causes problems if i can’t, because then the player can never change direction, they can only strafe. hopefully this clears it up some more, I dont really know what tutorials you are talking about, and I dont need to spherically interpolate between rotations, doesnt have much of a use to me… though thank you for an answer at least
no one?
Can i please get some help?
using UnityEngine;
using System.Collections;
public class SurfaceWalker : MonoBehaviour {
public float turnSpeed = 120.0f;
public float walkSpeed = 10.0f;
public float yOffset = 1f;
void Update () {
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
transform.position = hit.point + transform.forward * (Input.GetAxis("Vertical")*walkSpeed*Time.deltaTime) + new Vector3(0,yOffset,0);
float angle = Input.GetAxis ("Horizontal") * Time.deltaTime * turnSpeed;
Quaternion delta = Quaternion.AngleAxis (angle, transform.up);
transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
transform.rotation = delta * transform.rotation;
}
}
}
Dude, thank you so much, this works perfectly!