[ SOLVED ]Parent which holds character controller rotates towards camera ( child ) is pointing
Hi guys. This script bellow works fine but to make it works it adds a speed to the character ( I want the character moves only when I press a button. If the speed is zero the script wouldn't works.
I already have a script which will make the character moves mapped to button( axis ) on the xbox controller. All that I need is another script ( or to have the script bellow corrected ).
I am doing a game for Oculus Rift and I realised it will be better if my character moves towards where the camera is pointing only when I press the button ( dealing with axis here ).
This script works fine but it will add a speed to the character ( I don't want that. I would like to move the character only when I press a button). If the speed is zero the parent where the character controller is placed wouldn't rotates where the camera is facing.
I really appreciate any help you can provide.
using System.Collections; using UnityEngine;
public class cameraRiftmoves : MonoBehaviour { public float speed = 0; // moves 10 units every second
// Use this for initialization
private void Start()
{
}
// Update is called once per frame
private void Update()
{
transform.Translate(Camera.main.transform.forward * Time.deltaTime * speed, Space.World);
}
}
I think the problem is with " Camera.main.transform.forward " . I just want the Parent where the Character Controller is to take the Camera direction not sending the Character forward. This script will work only when the Character goes forward. " I tried " transform.rotation = Camera.main.transform.rotation; " but it didn't works but
the Character keeping rotating and I think this occur because it has to be in world space... how I can fix that.
Answer by gosolo2 · Jun 26, 2017 at 12:55 PM
NEVER MINDI. I GOT IT
All that you need is just one FS$$anonymous$$ placed on the capsule with 3 actions. One Variable ( Vector3 ) in this case called $$anonymous$$OVE$$anonymous$$ENT. That is all.
Your answer
Follow this Question
Related Questions
camera script problems and can't see the selected object 0 Answers
Character controller for fixed perspective camera (moving relative to arbitrary point on screen) 0 Answers
How do I get Oculus Touch Controllers to move my character controller? 0 Answers
How can i move my camera forward independent of its pitch? 1 Answer