x


Strange New Expression Error, with regards to Vector3

Hello all. I am running into a strange error when calling new on a Vector3. I am getting the error CS1526: A new expression requires () or [] after type, which usually indicates a missing (), but from what I have seen Vector 3 never requires this. Here is the code in question:

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

 public float speed = 10.0f;
 public float gravity = 21.0f; //downward force
 public float terminalVelocity = 20.0f; //max downward force
 public float jumpSpeed=6f;

 public Vector3 MoveVector {get; set;}
 public float VerticalVelocity {get; set;}


 void Awake() {
 CharacterController controller=gameObject.GetComponent("CharacterController") as CharacterController; 
 }

 void Update() {

 //These next three lines lock out the z-axis
 Vector3 pos = transform.position;
      pos.z = 0;
      transform.position = pos;

 //Call the functions that control movement
 checkMovement();
 HandleActionInput();
 processMovement();
 }

 void checkMovement() {
 float deadZone=0.1f;
 VerticalVelocity = MoveVector.y;
 MoveVector=Vector3.zero;
 if(Input.GetAxis("Horizontal")> deadZone || Input.GetAxis("Horizontal")<-deadZone) {
 MoveVector +=new Vector3(Input.GetAxis("Horizontal"),0,0);
 }
 }

 void HandleActionInput() {
 if(Input.GetButton("Jump"))
 jump();
 }

 void processMovement(){
 //transform move vector into world-space relative to character rotation
 MoveVector = transform.TransformDirection(MoveVector);
 //normalize movevector if magnitude >1
 if(MoveVector.magnitude > 1){
 MoveVector = Vector3.Normalize(MoveVector);
 }
 //multiply moveVector by moveSpeed
 MoveVector *= MoveSpeed;
 //reapply vertical velocity to moveVector.y
 MoveVector = new Vector3(MoveVector.x, VerticalVelocity, MoveVector.z);
 //apply gravity
 applyGravity();
 //move character in world-space
 CharacterController.Move(MoveVector * Time.deltaTime);
 }

 void applyGravity(){
 if(MoveVector.y > -TerminalVelocity){
 MoveVector = new Vector3(MoveVector.x, (MoveVector.y – Gravity * Time.deltaTime), MoveVector.z);
 }
 if(CharacterController.isGrounded && MoveVector.y < -1){
 MoveVector = new Vector3(MoveVector.x, (-1), MoveVector.z);
 }
 }

 public void jump(){
 if(CharacterController.isGrounded){
 VerticalVelocity = JumpSpeed;
 }
 }
}

The line in question is in the apply gravity method:


    MoveVector = new Vector3(MoveVector.x, (MoveVector.y – Gravity * Time.deltaTime), MoveVector.z);

The error message is:

CS1526: A new expression requires () or [] after type

Can someone explain to me why this is happening? Thanks.

more ▼

asked Jul 12 '12 at 07:54 PM

Nass gravatar image

Nass
1 1 3

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x575
x120

asked: Jul 12 '12 at 07:54 PM

Seen: 246 times

Last Updated: Jul 12 '12 at 07:54 PM