Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nass · Jul 12, 2012 at 07:54 PM · vector3new

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Does making a new Vector3() have an impact on performance? 3 Answers

I'm used to Java/Processing, some help with new() please 2 Answers

Middle of screen vector 3? 2 Answers

Array or Data Structure with Vector3 as keys 2 Answers

How to use SimpleMove randomly move an NPC? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges