- Home /
Forward or Reverse Character Position Skateboard Game
Esentially i want to be able to come back down the ramp in either reverse or forward position and still be able to perform my maneuvers. As it sits my character translates to a forward position each time.( my code says to do this) Any tips on what i can or what i should be looking at ? I cant work out what i should be doing.
Web build of the game so far , press space to move x,c,v,b do moves while in air....UP and Down arrows move across the ramp but in air they rotate as well.
http://home.iprimus.com.au/peanutt/Skate/Completewebbuild.html
var horizontal = Input.GetAxis ("Horizontal");
horizontal += -Input.acceleration.y * accelerometerScale;
if (vertical)
{
var toRotate = horizontal * rotateSpeed * inAirRotateScale * Time.deltaTime;
vertRotation += Mathf.Abs(toRotate);
skater.Rotate(0, toRotate, 0);
}
//else
//trans.Rotate(0, horizontal * rotateSpeed * Time.deltaTime, 0);
//transform.Rotate(0, Input.GetAxis("Vertical") * RotationSpeed * Time.deltaTime, 0);
var moveDirection = trans.forward * speed;
var upright = Vector3.Dot(Vector3.up, trans.forward);
// We have to fake gravity when the character is vertical, since the CharacterController doesn't rotate
moveDirection += Vector3.Lerp(Physics.gravity, Mathf.Sign(upright) * -trans.forward * Physics.gravity.magnitude,
Mathf.Clamp01(Mathf.Abs(upright)));
if (Vector3.Dot(Vector3.up, targetForward) >= 0.9
&& speed > maxSpeed * 0.6
&& !vertical)
{
vertical = true;
vertRotation = 90;
var addPoints = verticalPoints;
trickPoints.Add(addPoints);
trickLabel.Add("VERT! +" + addPoints);
trickAudio.PlayOneShot(ollieSound);
var vertOriginalRot = skater.rotation;
}
if ( vertical )
{
moveDirection = Vector3.up * speed;
speed -= Time.deltaTime * Physics.gravity.magnitude;
if (Input.GetKeyUp(KeyCode.V) )
skate360();
if (Input.GetKeyUp(KeyCode.B) )
skater180();
if (Input.GetKeyUp(KeyCode.C) )
Ollie();
if (Input.GetKeyUp(KeyCode.X) )
Kickflip();
}
character.Move(moveDirection * Time.deltaTime);
if (vertical && character.isGrounded )
{
vertical = false;
trans.forward = -trans.forward;
speed *= -1;
var skaterRot = Vector3.Dot(trans.forward, skater.forward);
if (Mathf.Abs(skaterRot) < oneEightyThreshold)
Fall();
else if (vertRotation > 180.0 * oneEightyThreshold)
{
var multiplier = Mathf.Round(vertRotation / 180.0);
// Player successfully rotated around
addPoints = oneEightyPoints * multiplier;
trickPoints.Add(addPoints);
trickLabel.Add(String.Format("{0}! +{1}", 180 * multiplier, addPoints));
}
//skater.forward = trans.forward;
}
var ray = new Ray(trans.position + Vector3.up, -Vector3.up);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 3, raycastMask))
{
targetRight = Vector3.Cross(hit.normal, trans.forward);
targetForward = Vector3.Cross(targetRight, hit.normal);
targetBack = Vector3.Cross(targetLeft, hit.normal);
targetLeft = Vector3.Cross(hit.normal, -transform.forward);
print ("There is something in front of the object!");
print("We are grounded");
//targetForward.transform.rotation = Quaternion.Slerp(transform.rotation,targetRot, Time.deltaTime * 1);
//transform.Rotate(0.0f, 0.0f, delta_degree).
// direction = transform.up;
if (character.isGrounded )
targetRot = Quaternion.LookRotation(targetForward, hit.normal);
}
Debug.DrawRay(trans.position, targetRight * 10, Color.green);
Debug.DrawRay(trans.position, targetForward * 10, Color.white);
Debug.DrawRay(trans.position, targetLeft * 10, Color.red);
Debug.DrawRay(trans.position, targetBack * 10, Color.blue);
trans.rotation = Quaternion.Slerp(trans.rotation, targetRot, Time.deltaTime * 4.6);
if ( character.isGrounded )
{
// Stop the character when he has slowed down enough
if (Mathf.Abs( speed ) <= 0.3)
{
speed = 0;
anim.Play("standing_board_up");
loopAudio.Stop();
}
else
// Simple friction to slow character down
speed -= decayRate * Time.deltaTime * speed;
}
if (currentInstruction == InstructionOrder.DONE)
showInstructions = false;
}
I think its about on collision or landing getting the new vect9r3 and assigning that as your new move direction.
I was wondering if this works in the new unity5 personal edition? I was doing the same kind of project and upgraded and now I can't even get into the air because I get stuck non the ramp. Its like the transform for gravity is messed up
Your answer

Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
C# FP_Camera not following Character Controller 0 Answers
Why is my character's y axis randomly changing? 1 Answer
How to detect on which side my character controller was hit? 1 Answer
help pls beginner, keyboard script 2 Answers