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 FlyElephant · Sep 01, 2015 at 09:06 AM · vectormouse input

Unity 2D jump in mouse direction

I like to write a scrip (C#) to move a game object in the mouse direction no constant force more a jump or teleport
im not good but i think it should work but it dont work and it make some strange thinks ;D can somebody help me ? This is my script Very simple script

using UnityEngine; using System.Collections;

public class jump : MonoBehaviour {

 public float range ;
 public Vector2 posi;

 void Update (){
     posi = Input.mousePosition * range;
     if (Input.GetKeyDown (KeyCode.Q)){
         transform.position =posi;
         }
     }

}

Comment
Add comment · Show 6
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
avatar image FlyElephant · Aug 31, 2015 at 02:53 PM 0
Share

*strange things my English is bad ;D Sorry

avatar image Mikilo · Sep 01, 2015 at 09:10 AM 0
Share

What is a mouse direction?

avatar image Mikilo · Sep 01, 2015 at 10:41 AM 0
Share

The mouse position is 1 point.

A direction requires 2 points.

So, which direction do you want?

avatar image Mikilo · Sep 01, 2015 at 10:53 AM 0
Share

You should use comment to answer me, not a real Answer.

I don't understand what you are requesting.

First of all, you want to a GameObject in the mouse direction, did you mean mouse position?

For that, you can use things like that:

         transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);

It converts the position of the mouse on the screen (2 dimensions) in the world (3 dimensions).

avatar image FlyElephant · Sep 01, 2015 at 11:09 AM 0
Share

It walk in 2d Do you know the flash from leuge of legends ? I like to make a game like Zelda i would make a jump and the aim of the jump is the mouse Direktion thed you jump with a max range in de Direktion of the mouse

Show more comments

2 Replies

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

Answer by Mikilo · Sep 01, 2015 at 11:26 AM

First of all, you have the position of your GameObject character.

When you press Q, you need to get the position of where the mouse is pointing on your terrain, map, ground, or anything like that.

With that new point, you now have a direction. Just move your GameObject towards the direction, handling when you are the range is too high or not.

To achieve that, you can do this:

         RaycastHit    hit;

         if (Physics.Raycast(Camera.main, Camera.main.transform.forward, out hit, float.MaxValue) == true)
         {
             // Where you want to go.
             Vector3    direction = (hit.point - transform.position);
             
             // If higher than the range, clamp it.
             if (direction.magnitude > range)
                 transform.position = transform.position + direction.normalized * range;
             else
                 transform.position = transform.position + direction;
         }
Comment
Add comment · Show 4 · 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
avatar image FlyElephant · Sep 01, 2015 at 03:59 PM 1
Share

thenks for the great help ;) if you like i send you the game if it is ready ;D

avatar image Mikilo · Sep 01, 2015 at 04:11 PM 0
Share

You are welcome! =D

What kind of game is it?

avatar image FlyElephant · Sep 01, 2015 at 04:14 PM 0
Share

A RPG like Zelda but with a bit mor focus on storry :)

avatar image Mikilo · Sep 01, 2015 at 04:25 PM 0
Share

A Zelda like? It seems interesting, go for it!

avatar image
0

Answer by FlyElephant · Sep 01, 2015 at 10:34 AM

The mouse input Position or is this wrong ?

Comment
Add comment · Show 2 · 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
avatar image FlyElephant · Sep 01, 2015 at 10:45 AM 0
Share

always the current position of my mouse but only if i pres q the jump

avatar image FlyElephant · Sep 01, 2015 at 10:48 AM 0
Share

always the current position of my mouse on the screen

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to calculate the tilt angle of an object? 0 Answers

iOS shader: 'Vector' syntax error (on gles) 1 Answer

Why does if (Input.GetMouseButton) doesn't work on my unity? 1 Answer

Confusion trying to set position at an angle 1 Answer

How do i rotate an object towards mouse? 2 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