Dive Board
-
DiveFPSController.js ...
DiveFPSController.js ...
by Ianmcmill on Jan 26th, 2014 17:19 PM
Hello,
as I am fairly new to coding and just scratching the surface of C# I have some problems with this Javascript from the demo project.
I know I may not have the right to criticise any code but in this case I can't help my self. Maybe I am just to much of a nub but is here anybody else that struggles with this FPS javaScript ? There is no intending, no formatting, rare "comments".
I tried to convert it to C# but I clearly lack the competence.
At least I got the intends and formating halfway decent....and got rid of this "die" function.
Anyways this throughs some errors. As the auther seems not to care about the readability, is here anybody that could help me out ?<br />using UnityEngine;<br />using System.Collections;<br /><br /><br />[RequireComponent(typeof(CharacterController))]<br />public class DiveFPSController : MonoBehaviour <br />{<br /> Vector3 inputMoveDirection;<br /> bool inputJump = false;<br /> bool grounded = false;<br /> float downmovement = 0.1f;<br /> Vector3 velocity;<br /><br /> public float max_speed = 0.1f;<br /> public float max_speed_air = 0.13f;<br /> public float max_speed_ground = 0.1f;<br /> public float acceleration = 10;<br /> public float acceleration_air = 10;<br /> public float gravity = -0.18f;<br /> public float friction = 0.8f;<br /> public GameObject cameraObject;<br /> private CharacterController controller;<br /> public Vector3 groundNormal;<br /> public float jumpspeed = 0.16f;<br /> public bool stopmovingup = false;<br /> public float fallkillspeed = -0.38f;<br /> public CollisionFlags collisionFlags; <br /><br /> public GameObject ground_gameobject=null;<br /> public Vector3 last_ground_pos;<br /> private float jumpcommand = 0;<br /> public bool floating = false;<br /><br /> public int autowalk=0;<br /> public float inhibit_autowalk = 1;<br /> public int reload_once=0;<br /><br /> void Awake ()<br /> {<br /> controller = GetComponent<CharacterController>();<br /> Debug.Log("Controller Slopelimit"+controller.slopeLimit);<br /> }<br /><br /> void JumpUp ()<br /> {<br /> jumpcommand=1;<br /> }<br /><br /> void Start ()<br /> {<br /> reload_once=0;<br /> }<br /><br /> void OnControllerColliderHit (ControllerColliderHit hit)<br /> {<br /> if (hit.normal.y > 0 && hit.moveDirection.y < 0) <br /> {<br /> groundNormal = hit.normal;<br /> grounded=true; <br /> ground_gameobject=hit.gameObject;<br /> <br /> //print("Landed on: ground"+ground_gameobject.name);<br /> stopmovingup=false;<br /> }<br /> }<br /><br /> float fadeduration = 2.0f; // fade duration in seconds<br /><br /> void Update ()<br /> {<br /> Debug.DrawLine (transform.position, transform.position+groundNormal, Color.red);<br /> //print("GroundNormal y" +groundNormal.y);<br /><br /> Vector3 directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));<br /><br /> if (directionVector != Vector3.zero) <br /> {<br /> // Get the length of the directon vector and then normalize it<br /> // Dividing by the length is cheaper than normalizing when we already have the length anyway<br /> float directionLength = directionVector.magnitude;<br /> directionVector = directionVector / directionLength;<br /> <br /> // Make sure the length is no bigger than 1<br /> directionLength = Mathf.Min(1, directionLength);<br /> <br /> // Make the input vector more sensitive towards the extremes and less sensitive in the middle<br /> // This makes it easier to control slow speeds when using analog sticks<br /> directionLength = directionLength * directionLength;<br /> <br /> // Multiply the normalized direction vector by the modified length<br /> directionVector = directionVector * directionLength;<br /> }<br /><br /> // Apply the direction to the CharacterMotor<br /> inputMoveDirection = directionVector;<br /> inputJump = Input.GetButton("Jump");<br /> <br /> if(jumpcommand==1)<br /> {<br /> inputJump=true; <br /> jumpcommand=0;<br /> }<br /> <br /> <br /> if (floating)<br /> {<br /> velocity.y=0.1f;<br /> }<br /><br /> if (inputJump&&grounded)<br /> {<br /> velocity.y+=jumpspeed;<br /> velocity.z*=1.5f;<br /><br /> //print ("Jump");<br /> grounded=false;<br /> }<br /> <br /> <br /> if (grounded)<br /> {<br /> velocity+=inputMoveDirection*acceleration*Time.deltaTime;<br /> }<br /> else<br /> {<br /> velocity+=inputMoveDirection*acceleration_air*Time.deltaTime;<br /> }<br /> <br /> Vector3 translation = new Vector3(velocity.x,0,velocity.z);<br /> <br /> translation = Vector3.Lerp(Vector3(0,0,0),translation,friction);<br /> <br /> velocity.x=translation.x;<br /> velocity.z=translation.z;<br /> velocity.y = velocity.y+gravity*Time.deltaTime;<br /> //print ("Time deltatime "+Time.deltaTime);<br /> <br /> <br /> if (grounded)<br /> {<br /> velocity.y=0;<br /> //print ("Vel y "+velocity.y);<br /> }<br /> <br /> if (grounded)<br /> {<br /> max_speed=max_speed_ground;<br /> }<br /><br /> if (!grounded)<br /> {<br /> max_speed=max_speed_air;<br /> }<br /><br /> if (translation.magnitude>max_speed)<br /> {<br /> translation=translation/translation.magnitude;<br /> translation=translation*max_speed;<br /> }<br /><br /> velocity.x=translation.x;<br /> velocity.z=translation.z;<br /> translation.y=velocity.y;<br /> <br /> Quaternion yrotation_camera= Quaternion.Euler(0, cameraObject.transform.rotation.eulerAngles.y, 0);<br /> //transform.position+=yrotation_camera*translation;<br /><br /> Vector3 platformdelta;<br /> <br /> if(ground_gameobject!=null) <br /> {<br /> print("ground object ungleich null");<br /> platformdelta=ground_gameobject.transform.position-last_ground_pos;<br /> }<br /> <br /> //if (!grounded)platformdelta=Vector3.zero;<br /> <br /> <br /> //MAKE A MOVE!<br /> <br /> collisionFlags=controller.Move(yrotation_camera*translation+platformdelta);<br /> <br /> <br /> if (collisionFlags & CollisionFlags.CollidedAbove)<br /> {<br /> if (stopmovingup==false)<br /> {<br /> print ("ControllerColliderHit"); <br /> velocity.y=0; <br /> stopmovingup=true;<br /> }<br /> }<br /> <br /> if (ground_gameobject!=null && !grounded)<br /> {<br /> ground_gameobject=null;<br /> }<br /><br /> if(ground_gameobject!=null)<br /> {<br /> last_ground_pos=ground_gameobject.transform.position; <br /> }<br /> }<br /><br /><br /> void LateUpdate ()<br /> {<br /> //groundNormal=Vector3.zero;<br /> }<br /> void OnGUI ()<br /> {<br /> // GUI.Label ( new Rect(10, 10, 400, 20), "isgrounded "+grounded+ " velocity.y "+velocity.y+" collsionbelow "+ (collisionFlags & CollisionFlags.Below) );<br /> Event e = Event.current;<br /><br /> if (e.isKey) <br /> {<br /> Debug.Log("Detected key code: " + e.keyCode);<br /> GUI.Label ( new Rect(10, 10, 400, 20), "Keycode ="+ e.keyCode );<br /> }<br /> <br /> }<br /><br /><br /> void OnTriggerEnter ( Collider other )<br /> {<br /><br /> if (other.name == "Float") <br /> {<br /> floating=true; <br /> inhibit_autowalk=0.1f;<br /> }<br /> }<br /><br /> void OnTriggerExit ( Collider other )<br /> {<br /> if (other.name == "Float") <br /> {<br /> floating=false; <br /> inhibit_autowalk=1;<br /> }<br /> }<br />}<br />
Assets/_Scripts/DiveFPSController.cs(131,44): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Assets/_Scripts/DiveFPSController.cs(131,39): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' has some invalid arguments
Assets/_Scripts/DiveFPSController.cs(131,39): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Vector3'
Assets/_Scripts/DiveFPSController.cs(181,77): error CS0165: Use of unassigned local variable `platformdelta'
Assets/_Scripts/DiveFPSController.cs(184,17): error CS0029: Cannot implicitly convert type `UnityEngine.CollisionFlags' to `bool'
Ianmcmill
Posts: 10
Joined: 19.12.2013
Re: DiveFPSController.js ...
by henny1234 on Jun 15th, 2022 06:54 AM
I have read some of your posts and they have been quite beneficial for me in my life. If you want to play music related games, you can try heardle, it will make you more comfortable
henny1234
Posts: 4
Joined: 15.06.2022
RECENT TOPICS
Men’s Thobes and Islamic Clothing Culture in the UK
Scrap car removal Edmonton
Scrap metal Surrey
STATISTICS
Total posts: 171511
Total topics: 41565
Total members: 44823
Newest member: Daniel G.
Meet the