Unity pong game ball physics slowing issue [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In my game for pong, the ball is supposed to bounce and never become slower. However, the ball is steadily slowing down over time. I will put an image of the ball object and the scripts.
Here is the ball properties on the left
Here is the ball script
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour
{
public float ballVelocity = 3000;
Rigidbody rb;
bool isPlay;
int randInt;
void Awake()
{
rb = GetComponent<Rigidbody>();
randInt = Random.Range(1,3);
}
void Update()
{
if (Input.GetMouseButton(0) && isPlay == false)
{
transform.parent = null;
isPlay = true;
rb.isKinematic = false;
if (randInt == 1)
{
rb.AddForce(new Vector3(ballVelocity, ballVelocity, 0));
}
if (randInt == 2)
{
rb.AddForce(new Vector3(-ballVelocity, -ballVelocity, 0));
}
}
}
}
and here is the bounce physics image
and since I have no idea why it won't work, here is my physics project settings
I have been stuck and am new to unity so any help would be awesome! If you need any more info, comment!

Go to you assets folder and create a PhysicMaterial and set both Frictions to (Static and Dynamic) to 0 and Bounciness to 0.

Related

I am making a "boss fight" in unity2d. I wanted my player to get Iframes on hit. And it works but it bugs out so quickly. Any idea why it gets bugged? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
So basically i did a character with 3 health. It seemed like this character needed iframes because he was getting stuck to death very quickly. So i made it so when he gets hit he is untouchable for 5 seconds and it worked but was bugging out too frequently (in about every 8-9 hits).
What i mean by bugging out is... My character did not get hit at all, infinitely. until my character died or i restarted the game.
Here is my code
If you need any of the other codes just say it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Iframes : MonoBehaviour
{
Renderer rend;
Color c;
GameObject character;
// Start is called before the first frame update
void Start()
{
rend = GetComponent<Renderer> ();
c = rend.material.color;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
StartCoroutine("GetInvulnerable");
}
}
IEnumerator GetInvulnerable()
{
Physics2D.IgnoreLayerCollision(8, 9, true);
yield return new WaitForSeconds(3f);
Physics2D.IgnoreLayerCollision(8, 9, false);
}
}

Why is the compiler telling me that there is no definition for .Enabled? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I'm following Brackeys' tutorial on making a 3D game in Unity on Youtube and I'm up to the E05 (the collisions video) and I'm trying to make it so when you collide with the obstacle then the player movement is disabled. Here is the code:
Player Movement Code:
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if(Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
}
Player Collision Code:
public PlayerMovement movement;
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.Enabled = false;
}
}
However when I go back to Unity, the compiler tells me that PlayerMovement contains no definition for .Enabled. I'm sure I followed the video correctly, can anybody help?
You don't followed video corretly....
You must write enabled in lowercase, Enabled in upper case don't exit.
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
}
}

How can i make a player stop moving when it touchs a collider? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
So i was wondering if there is a way to make a player move infinitely with just one click and just stop when colliding with another collider.
You can create a global property:
bool movePlayer = false;
In FixedUpdate method you can detect a mouse click and change movePlayer to true, and move the player if it values true:
void FixedUpdate() {
if (Input.GetMouseButtonDown(0))
movePlayer = true;
if (movePlayer) {
//move the player here, maybe with Translate method
}
}
With OnTriggerEnter method you can detect the collision and change movePlayer to false:
void OnTriggerEnter(Collider other) {
//you can check for some particular object or avoid this if
if (other.gameObject.name == "SomeObject")
movePlayer = false;
}

please help me with my game my game have a problem [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am making a objectpoolingManager which is supposed to put bullets under an empty object called objectpoolingManager and in my code i wrote that it must enable the bullet when i click the mouse button then after 2 second it will diables the bullet now my problem is that it is always disabled.
public GameObject bulletPrefab;
public int bulletAmount = 20;
private List<GameObject> bullets;
// Start is called before the first frame update
void Awake()
{
instance = this;
bullets = new List<GameObject>(bulletAmount);
for (int i = 0; i < bulletAmount;i++)
{
GameObject prefabInstance = Instantiate (bulletPrefab);
prefabInstance.transform.SetParent (transform);
prefabInstance.SetActive(false);
}
bullets.Add(bulletPrefab);
}
public GameObject GetBullet ()
{
foreach (GameObject bullet in bullets)
{
if(!bullet.activeInHierarchy)
{
bullet.SetActive (true);
return bullet;
}
}
GameObject prefabInstance = Instantiate (bulletPrefab);
prefabInstance.transform.SetParent (transform);
bullets.Add(bulletPrefab);
return prefabInstance;
}
}
Your getter/setter of objects in your pool manager should not instantiate or destroy gamobjects, but enable and disable them. That is the purpose of pooling.
It makes more sense to EnQueue/deQueue them and activate/deactivate like this.
private Queue<GameObject> objPool;
private Queue<GameObject> activeObj;
//get from pool
public GameObject GetObjFromPool(Vector3 newPosition, Quaternion newRotation)
{
GameObject newObject = objPool.Dequeue();
newObject.SetActive(true);
newObject.transform.SetPositionAndRotation(newPosition, newRotation);
//keep actives to be retrieved
activeObj.Enqueue(newObject);
return newObject;
}
//return to pool
public void ReturnObjToPool(GameObject go)
{
go.SetActive(false);
objPool.Enqueue(go);
}
Find this question in case its helpfull.
You can find plenty of pooling examples if you goolgle that up. Here is one.

How give touch position for particle systems [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How give touch position for particle systems,
I need particle systems follow touch move,
please advise me that something
this script is attached on particle system
void Update () {
transform.position = new Vector2 (Input.GetTouch (0).position.x, Input.GetTouch (0).position.y);
}
Camera cam = Camera.Main;
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchPos = Input.GetTouch(0).Position;
transform.position = cam.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, 0));
}
}
This work any better?

Categories