Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im working on a character in unity on a 2 D project that involves a character moving with W A S D and it needs

Im working on a character in unity on a 2D project that involves a character moving with W A S D and it needs to work around the vectors but I've ran into errors in my code. Below is my code what is the issue.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
const float speed =1.0f;
Vector2 velocity;
// Start is called before the first frame update
void Start()
{
velocity = speed * new Vector2(1.0f,0.0f);
}
// Update is called once per frame
void Update()
{
Debug.Log("Hi");
if (Input.GetKey("w"))
{
velocity =-1* velocity;
}
transform.position = transform.position +(velocity * Time.deltaTime);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

Why is delayed containment not recommended for most CSIRTs?

Answered: 1 week ago