- Home /
Question by
skyEchuuu · Dec 14, 2013 at 10:36 PM ·
c#movementplatformerside-scrolling
What is the problem here ?( move script, c#, basic, platformer)
Hi guys, I wrote a scrip that moves character horizontal. But its does not work correctly and i didn't see where is the problem :( there is no error about code. And other code that i wrote with physics move is working correctly(error is not respect to my input settings) Hopefully you can help me . Thanks everyone.
using UnityEngine;
using System.Collections;
public class moveTest3D : MonoBehaviour
{
public float groundRay=10f;
public bool isGrounded=true;
public bool isSwimming=false;
public bool isJumping=false;
public bool isRunning=false;
public float acc=10f;
public float groundMaxSpeed=10f;
public float groundJump=20f;
void Start(){
}////////////////////////////start
void Update(){
RaycastHit hit;
Ray grounding = new Ray(transform.position, Vector3.down);
Debug.DrawRay(transform.position, Vector3.down * groundRay);
if(Physics.Raycast(grounding, out hit, groundRay)){
if(hit.collider.tag == "ground"){
isGrounded=true;
}else{ isGrounded=false;}
}
if(Input.GetButtonDown("Jump") && isGrounded){
isJumping = true;
}
}///////////////////////////update
void FixedUpdate(){
float horizontalInput = Input.GetAxis("Horizontal");
float run = horizontalInput * acc;
if(run>groundMaxSpeed){
run=groundMaxSpeed;
isRunning=true;
}
if(isRunning && isGrounded){
run *= Time.deltaTime;
transform.Translate(run,0,0);
}
}//////////////////////////fixedupdate
}////////////////////////// Mono Behaviour
Comment