Dive Board
-
I need help with some Scripts
I need help with some Scripts
by redsch on Jan 18th, 2014 20:36 PM
Hello, I just started devoloping a game with the Unity 3D software but I'm a bit noob on programation, can you tell me the scripts that you used for the movement system (like the one that is used in "The High" that allows you activate and disactivate movement) or how have you done for doing it. If its too hard or long to explain, can you just pass-me the scripts and tell how to use them. I would like it so much.
Thank you for your attention and sorry for mistakes in writting (english is not my native language).
Your Sincerly,
Ramon Alcaide
PS: I would like to know about the jumping system too (the one that is used in "The High" too) Thank You again.redsch
Posts: 2
Joined: 18.01.2014
Re: I need help with some Scripts
by Stefan on Jan 27th, 2014 13:26 PM
I will check again if the functionality is in the Dive Unity Demo.
For next release there might be an example scene of that.Stefan
Posts: 129
Joined: 30.06.2013
Re: I need help with some Scripts
by Holger on Jan 29th, 2014 16:24 PM
It's not too hard to create a first person controller in Unity.
Take a look here:
http://www.youtube.com/watch?v=mbm9lPB5GPwHolger
Posts: 6
Joined: 27.01.2014
Re: I need help with some Scripts
by Ianmcmill on Jan 29th, 2014 17:58 PM
Those tutorials are really good. Another good FPS tutorial series (and complete) is : http://www.youtube.com/playlist?list=PL7AE076AFAFD3C305 . He uses rigidbody.
My problem is, how do I get my character to rotate with the camera rotation and move in the direction the camera is looking when pressing forward.
I have two scripts. One is the Controller, the other is a mouse look script to test on the computer.
Now, how do I use the camera to rotate the character with the OpenDiveSensor ????
Simple character controller:using UnityEngine;<br />using System.Collections;<br /><br />[RequireComponent (typeof(CharacterController))]<br />public class FirstPersonController : MonoBehaviour {<br /><br /> //Movement<br /> public float movementSpeed = 5.0f;<br /> public float strafeSpeed = 3.0f;<br /> public float mouseSensitivity = 5.0f;<br /> public float jumpSpeed = 20.0f;<br /><br /> public GameObject cameraObject;<br /><br /> float verticalVelocity = 0;<br /> <br /> CharacterController characterController;<br /><br /><br /><br /> // Use this for initialization<br /><br /> void Start () <br /> {<br /> characterController = GetComponent<CharacterController>();<br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> // Rotation<br /> //rotate the character (object the script is attached to) along the "quaternion.euler Y of the FPSMouseLook script<br /> //the Y axis is stored in "horizontalRotation" in the FPSMouseLook script.<br /> // What do I have to do to get the actuall camera rotation to transform to the character rotation ?????<br /> transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent<FPSMouseLook>().horizontalRotation,0); <br /><br /> // Movement<br /> //Vertical input for forward and backward movement<br /> //Horizontal input for side strafing movement<br /> float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed; <br /> float sideSpeed = Input.GetAxis("Horizontal") * strafeSpeed;<br /> <br /> verticalVelocity += Physics.gravity.y * Time.deltaTime;<br /> <br /> if( characterController.isGrounded && Input.GetButton("Jump") ) {<br /> verticalVelocity = jumpSpeed;<br /> }<br /> <br /> Vector3 speed = new Vector3( sideSpeed, verticalVelocity, forwardSpeed );<br /> <br /> speed = transform.rotation * speed;<br /> <br /> characterController.Move( speed * Time.deltaTime );<br /> }<br />}<br />
Mouse scriptusing UnityEngine;<br />using System.Collections;<br /><br />public class FPSMouseLook : MonoBehaviour <br />{<br /><br /> public float mouseSensitivity = 5.0f;<br /> public float verticalRotation = 0;<br /> public float horizontalRotation = 0;<br /><br /> public float upDownRange = 60.0f;<br /><br /><br /><br /> // Use this for initialization<br /> void Start () <br /> {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () <br /> {<br /> horizontalRotation += Input.GetAxis ("Mouse X") * mouseSensitivity;<br /><br /> verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;<br /> verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);<br /><br /> transform.rotation = Quaternion.Euler(verticalRotation,horizontalRotation,0);<br /><br /> }<br />}<br />
Ianmcmill
Posts: 10
Joined: 19.12.2013
Re: I need help with some Scripts
by Ianmcmill on Jan 29th, 2014 18:46 PM
Okay I figured it out somehow.
I replaced in Update()transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent<FPSMouseLook>().horizontalRotation,0); <br />
withtransform.rotation = Quaternion.Euler(0, cameraObject.transform.rotation.eulerAngles.y,0);
This way I don't have to make a GetComponent. The camera object (Dive_Camera object) has to be set in the inspector.Ianmcmill
Posts: 10
Joined: 19.12.2013
Re: I need help with some Scripts
by Holger on Jan 30th, 2014 09:43 AM
Maybe you can use Vector3.forward to go in the direction of the camera?
Quaternion angle = rotTo * startAngle;
Vector3 tdirection = angle * Vector3.forward;
transform.position = z + tdirection;
Where z is the distance.Holger
Posts: 6
Joined: 27.01.2014
RECENT TOPICS
الخيار المثالي للمسافرين من رجال الأعمال والباحثين عن الترفيه
Mythen und Realität: die ganze Wahrheit über Payeer
فنادق مكة رخيصة وقريبة من الحرم – تجربة مريحة دون تكلفة مرتفعة
STATISTICS
Total posts: 171540
Total topics: 41572
Total members: 44832
Newest member: Daniel G.
Rencontrez la famille Durovis Dive et transformer votre appareil mobile en un casque de réalité virtuelle. jeux d'expérience et 360 vidéos ° en VR sur votre propre smartphone ou tablette.