Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by deadminer · Feb 22, 2017 at 09:15 PM · movement2d gamecontrolsanglesisometric

How can I move my 2D car in 16 fixed angles like in Retro City Rampage

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AnotherTestScript : MonoBehaviour {
 
     Rigidbody2D body;
     public float gears = 1f;
     public float acceleration = 0f;
     //Views:
     public SpriteRenderer spr;
 
     public Sprite view1;
     public Sprite view2;
     public Sprite view3;
     public Sprite view4;
     public Sprite view5;
     public Sprite view6;
     public Sprite view7;
     public Sprite view8;
     public Sprite view9;
     public Sprite view10;
     public Sprite view11;
     public Sprite view12;
     public Sprite view13;
     public Sprite view14;
     public Sprite view15;
     public Sprite view16;
 
     public void Awake()
     {
         body = GetComponent<Rigidbody2D>();
     }
 
 
     // Use this for initialization
 
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
 
         float moveHorizontal = Input.GetAxisRaw("Horizontal");
         float moveVertical = Input.GetAxisRaw("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
         body.velocity = movement * gears;
 
 
         float h = gameObject.transform.position.x;
         float v = gameObject.transform.position.y;        
         //Vector2 inputVector = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
         //body.velocity = inputVector * 3 ;
 
         if (Input.GetKeyDown(KeyCode.A))
         {
             spr.sprite = view13;
              //h -= 1f;
 
         }
         if (Input.GetAxisRaw("Horizontal") < -0.5f && Input.GetAxisRaw("Vertical") > 0.5)
         {
             spr.sprite = view15;
 
         }
         if (Input.GetKey(KeyCode.W) == true)
         {
             spr.sprite = view1;
 
         }
         if (Input.GetKey(KeyCode.S) == true)
         {
             spr.sprite = view9;
 
         }
         if (Input.GetAxisRaw("Horizontal") > 0.5f)
         {
             spr.sprite = view5;
 
         }
 
 
     }
 
     }

This is my script. The sprite variables called 'view1', 'view2', 'view3', etc are where the car individual 16 isometric pixel sprites are stores. I wanted the cars to drive like they do in retro city rampage. for those of you who have not played retro city rampage, here is a video on the game from NerdCubed. Link: https://www.youtube.com/watch?v=56CrKrbRuIc

I want the driving to be like the driving in the game with individual angle movements and the controls will be like WSAD or the arrow keys. I don't know how to do this. Can you please help.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by jdean300 · Feb 23, 2017 at 12:27 AM

What you can do there is have a simulated car angle that moves continuously based on the input, like a typical racing game. Now take that simulated angle and use the following code to convert it into an integer direction which you use to select a sprite and travel direction.

 public static int GetDirection(float angle)
 {
        angle /= (360f / 16f);
 
        return (Mathf.RoundToInt(angle)) % 16;
 }
Comment
Add comment · Share
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

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

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Isometric Movent Issue 0 Answers

Isometric movement for MoveTowards 0 Answers

Player facing mouse with orthographic isometric camera 0 Answers

I can't make my character move 0 Answers

Lerp ignores collision and allows player to move through a wall. 0 Answers


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