Translating JavaScript into C#

Hey guys,

I’m new to Unity and currently trying to make a simple Pong type of game. However, the tutorial I’m following is in JavaScript and I’m having trouble translating this code…

using UnityEngine;
            using System.Collections;

public class Ball : MonoBehaviour 
{

         float cSpeed = 10.0f;
         float sFactor = 10.0f;
         static int playerScore = 0;
         static int enemyScore = 0;

         void Start()
{

}

         void Update()
{

         rigidbody.AddForce(10, 0, 0);
         cvel = rigidbody.velocity;                      // Errors: The names 'cvel' and 'tvel' do not exist
         tvel = cvel.normalized * cSpeed;         
         rigidbody.velocity = Vector3.Lerp(cvel, tvel, Time.deltaTime* sFactor);

I know this code does not work, but how would I go about declaring cvel and tvel? If anyone could translate
this code for me, I’d be extremely thankful.

float cvel = rigidbody.velocity; // They don’t exists… but now they do!!! :slight_smile:
float tvel = cvel.normalized * cSpeed; // gotta declare the temp variables like that

You probably want to go to the scripting forums though… much better place. I just happen to be around here.