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

dive-owner


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=mbm9lPB5GPw

Holger

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&#46;Collections;<br /><br />&#91;RequireComponent (typeof(CharacterController))&#93;<br />public class FirstPersonController &#58; MonoBehaviour {<br /><br />	//Movement<br />	public float movementSpeed = 5&#46;0f;<br />	public float strafeSpeed = 3&#46;0f;<br />	public float mouseSensitivity = 5&#46;0f;<br />	public float jumpSpeed = 20&#46;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&lt;CharacterController&gt;();<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 &quot;quaternion&#46;euler Y of the FPSMouseLook script<br />               //the Y axis is stored in &quot;horizontalRotation&quot; in the FPSMouseLook script&#46;<br />                // What do I have to do to get the actuall camera rotation to transform to the character rotation ?????<br />		transform&#46;rotation = Quaternion&#46;Euler(0, cameraObject&#46;GetComponent&lt;FPSMouseLook&gt;()&#46;horizontalRotation,0);     <br /><br />		// Movement<br />		//Vertical input for forward and backward movement<br />		//Horizontal input for side strafing movement<br />		float forwardSpeed = Input&#46;GetAxis(&quot;Vertical&quot;) * movementSpeed; <br />		float sideSpeed = Input&#46;GetAxis(&quot;Horizontal&quot;) * strafeSpeed;<br />		<br />		verticalVelocity += Physics&#46;gravity&#46;y * Time&#46;deltaTime;<br />		<br />		if( characterController&#46;isGrounded &amp;&amp; Input&#46;GetButton(&quot;Jump&quot;) ) {<br />			verticalVelocity = jumpSpeed;<br />		}<br />		<br />		Vector3 speed = new Vector3( sideSpeed, verticalVelocity, forwardSpeed );<br />		<br />		speed = transform&#46;rotation * speed;<br />				<br />		characterController&#46;Move( speed * Time&#46;deltaTime );<br />	}<br />}<br />



Mouse script

using UnityEngine;<br />using System&#46;Collections;<br /><br />public class FPSMouseLook &#58; MonoBehaviour <br />{<br /><br />	public float mouseSensitivity = 5&#46;0f;<br />	public float verticalRotation = 0;<br />	public float horizontalRotation = 0;<br /><br />	public float upDownRange = 60&#46;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&#46;GetAxis (&quot;Mouse X&quot;) * mouseSensitivity;<br /><br />		verticalRotation -= Input&#46;GetAxis(&quot;Mouse Y&quot;) * mouseSensitivity;<br />		verticalRotation = Mathf&#46;Clamp(verticalRotation, -upDownRange, upDownRange);<br /><br />		transform&#46;rotation = Quaternion&#46;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&#46;rotation = Quaternion&#46;Euler(0, cameraObject&#46;GetComponent&lt;FPSMouseLook&gt;()&#46;horizontalRotation,0);  <br />


with

transform&#46;rotation = Quaternion&#46;Euler(0, cameraObject&#46;transform&#46;rotation&#46;eulerAngles&#46;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


STATISTICS


Total posts: 144357


Total topics: 34841


Total members: 42384


Newest member: Daniel G.